Day 5. I’m one fifth of the way through this challenge. Five days down, 20 to go.
Problem 1 started out not as I suspected, but I was able to quickly identify what was going on, correct and solve. Thankfully I did not have to struggle for 4.5 hours today, today’s struggle bus lasted for a whole 25 minutes.
In case you hadn’t figured it out yet, our search for the Chief Historian continues.
We’ve ended up in the basement, and thankfully for the most part avoided Milton and his Swingline stapler. We have again been accosted by someone in need of our help, this time an elf who can’t seem to get their safety manual to correctly print. After confirming they’re HP subscription was up to date and paid for, we dig in deeper. When new pages of the manual require printing, it must be done so in a specific order. Page ordering rules are presented in an x|y order, and it takes some time to understand what the rules are.
For example, 97|13 indicates that if both pages 97 and 13 are updated, page 97 must be printed before page 13. The second section lists the pages in each update. To help our new Elf friend get this to the printers as quickly as possible we need to start identifying updates that are already listed in their proper order.
Additionally, the Elves need to know the middle page number of each update being printed. Our goal is to find all the middle page numbers, and provide a sum of all of them as our solution.
Breaking down the problem, I identified the following:
With the above in mind, I took the following approach to solving this problem:
My initial two runs at this problem were giving me the wrong answer which came down to how I was parsing the file and splitting the page rules, from the pages to be updated. Unlike yesterday’s problem, I was able to update my function that does the splitting within two tries and get it working as it should be. One area here I need to be better at is keeping detailed notes when I’m working through issues like these. Partially due to this being a challenge, and me attempting to respond as quickly as possible, and part of this being me writing this article the following morning I’ve forgotten some of the fine detail in the changes I was making at the time. Even working under the premise of, “iterate quickly and break things”, I think there’s still time to slow down a bit, step back and understand and learn.
Now that we’ve helped the Elves get printing the correctly ordered pages, we have a little time in which we can help them fix the incorrectly ordered pages. Using much of our previous problem, we need to find the incorrectly ordered pages, and put them in their proper order. Similar to Problem 1, we’re also going to find the middle pages of the incorrectly ordered updates, and provide the sum of those middle pages.
Breaking down the problem, I identified the following:
My approach was similar to Problem 1, but updated to account for this particular problem:
Today’s challenge focused on us being able to recognize patterns and properly order pages. Key take away’s from today’s challenge for me were:
Today’s challenge built on lessons we’ve learned in previous day’s challenges, and enhanced our knowledge in areas such as string manipulation, data structures and algorithms.