C#C
C#4y ago
v0fbu1vm

❔ 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();
        }

Could I aggregate through
Input
to archive the same result? I'm learning the linq Aggregate, and just curious if I could archive the same result with an Aggregate?
Was this page helpful?