Advent 2023 Day 08 2 - checking the data
I wanted to add a bit to yesterday's post.
Yesterday I wrote that for part 2 I just counted the cycles from each starting point. If you looked at my code you'd notice that I didn't actually do that.
If you recall, nodes were identified by 3 letter codes. All nodes that
end in an A
like AAA or BBA are start nodes and all nodes that end
in a Z
are end nodes and we had to find the step, when starting
simultaneously at all start nodes, that they all get to end nodes.
To actually find a cycle for a given start point we'd have to:
- Start at the start node
- Follow the path until you get to an end node
- Continue following until you get back to that first end node
I didn't do that - my solution was simpler but it still worked. Further, if you read the problem statement, my solution shouldn't have worked for all cases.
Why did I write it and why did it work?
Because we were able to explore our data before solving the problem.
That's another thing I liked about this problem.
Sure, there are times when we're writing a program to solve for some unknown but often we have data, or at least some of the data and we can explore it to help shape our programs.
In this case we can grab a start node and track it using our part 1 solution, see how one or more "path" behaves and ultimately learn enough about the data to solve our problem.
I don't know how often teachers get to work with students on problems where they can use data exploration to tune their solutions, This is a great example of one.