Day 8
Today was by far my favourite challenge! Absolutely epic :) I've put my raw code above because I was quite proud of it.
Part 1 was annoyingly easy - but also humorous once I read the last sentence and realised how it essentially required a few lines! Not much to say here other than to notice that you can use a tuple in if statements to help speed things up - I saw some other people pre-defined the list and then use that in the statement. The part 1 solution is the first few lines of the program.
Now, Part 2 was hard but definitely fun on my brain. I know a brute force solution is possible which runs in under 10 seconds - a lot of people did this. However, I used the fact that some of the segments were shared between different numbers, so by grouping them I could quickly find out which number went where (I first created groups of numbers with the same amount of segments lit). Another way to think about it is that I looked at which numbers could be found in other numbers based off the segments lit. The things I did to figure out the numbers were:
Find the 1, 4, 7, and 8 - these all had a unique number of segments, hence their string length would be unique. I stored all of the strings in a dictionary as they key, with their corresponding number as the value.
Dealt with numbers which had 6 segments used - these were 0, 6, and 9. I recognised that of these three numbers, 6 was the only one which did not have both of the segments from numebr 1 lit up (which I identified in step 1), hence, using list comprehensions and tuples in if statements, I figured out which was 6.
I then had to find which was 0 and 9. Again, I recognised that out of the two, only 9 had all the same segments as lit up in 4 (which I identified in step 1), and used this fact to identify 9 leaving 0 as the other one.
I did a similar thing as steps 2 and 3, but with numbers that had 5 segments lit (2, 3, and 5). I used the fact that 3 was the only number to have all of the segments as 1, and 5 was the only number of the final two to have all of the segments of 4.
Now that I had a dictionary with every string mapped to one of 10 numbers, a simple look up from the output and some formatting was left to get my result. It was very satisfying! I particularly enjoyed this pattern spotting of the segments shared between numbers.
Now that the difficulty is increasing, this site may take longer to update every day ;)