❔ Write an Aggregate
public override string SolvePartOne()
{
HashSet<House> visited = new HashSet<House>()
{
new House(0, 0)
};
int x = 0,
y = 0;
foreach (char c in Input)
{
switch (c)
{
case '^': y++; break;
case 'v': y--; break;
case '>': x++; break;
case '<': x--; break;
default:
throw new InvalidDataException();
}
visited.Add(new House(x, y));
}
return visited.Count.ToString();
}public override string SolvePartOne()
{
HashSet<House> visited = new HashSet<House>()
{
new House(0, 0)
};
int x = 0,
y = 0;
foreach (char c in Input)
{
switch (c)
{
case '^': y++; break;
case 'v': y--; break;
case '>': x++; break;
case '<': x--; break;
default:
throw new InvalidDataException();
}
visited.Add(new House(x, y));
}
return visited.Count.ToString();
}Could I aggregate through
InputInput to archive the same result? I'm learning the linq AggregateAggregate, and just curious if I could archive the same result with an AggregateAggregate?