© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
6 replies
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();
        }
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
Input
to archive the same result? I'm learning the linq
Aggregate
Aggregate
, and just curious if I could archive the same result with an
Aggregate
Aggregate
?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

system.aggregate Exception
C#CC# / help
2y ago
How do I write out an object in Winforms
C#CC# / help
4y ago
Aggregate data grouped by a key
C#CC# / help
2y ago
❔ MONGO - Aggregate pipeline - GroupBy mutliple fields
C#CC# / help
3y ago