Day 20
Ah - today took a while, but at least it wasn't too hard!
For Part 1, I'm sure almost everyone fell into the same boat of not realising that the background of the image switches between on and off every enhancement due to the construction of the input! This was a smart move by Eric to make today's a little more challenging, a unique variation on Conway's game of life again.
One thing I did to make this easier was to initially replace all the characters with their respective digit, allowing for speedy conversions to take place. Then, I simply create a dictionary of the state of each coordinate from the input, and convert that into a defaultdict with the default value of 0 or 1 depending on the iteration. The background is initially off, so the first iteration uses a default value of 0, the next uses 1, and so on. As all of the coordinates update simultaneously, I need to create a copy of the dictionary to grab values from. I used deepcopy just to ensure a fresh dictionary is made and no python mutable nonsense happens :). Then, I go through each point in the bounding box (which increases by 1 in each axis) and set the coordinate tuple in the dictionary to the corresponding index from the instruction set. This is a long one-liner! It essentially forms a list with all 9 0s or 1s, and converts it into a coherent string. Then, it turns that into a decimal number which is used to index from x. Once all of this code has run, I just count the number of 1s in the values of the dictionary by summing the decimal numbers.
I found the defaultdict quite cool - the way you can use lambda to set the default value to whatever you want, and also how you can pass in a second parameter to convert a specific dictionary to a defaultdict.
Part 2, for me, was just a matter of swapping out the 2 with a 50 - it takes about 5 seconds to run. Unfortunately... I copied the wrong answer (the digit 0) and submitted that, leaving me with a 1-minute time out (enough time to ensure I had copied the correct answer!) :(
80% there... just 10 more stars until xmas :D