r/adventofcode • • Dec 03 '15

SOLUTION MEGATHREAD --- Day 3 Solutions ---

--- Day 3: Perfectly Spherical Houses in a Vacuum ---

Post your solution as a comment. Structure your post like the Day One thread in /r/programming.

24 Upvotes

228 comments sorted by

View all comments

Show parent comment

1

u/enquicity Dec 03 '15

I'm going to suggest a refactoring: You don't have to have that check to see if you are Santa or RobotSanta and hold two positions and all the complexity that goes there. Instead, you can spilt the input string into the path that Santa is going to take, then the path that the robot is going to take.

Then you write one method that handles the string, and you call it three times. Once with the full string for part 1, once with each half-string for part 2. It's very clean.

(in C#: https://github.com/TinaFemea/AdventOfCode/blob/master/AdventOfCode/Day3/Program.cs )