Day 3
Today was hard! Don't worry if you took a while, or could not understand part 2 :)
However, I managed to come 27th for p1, and 57th for p2, leaving me 73rd globally all time!
Today was a raw implementation challenge, designed to get you more fluent with a language. Part 1 was a bit of a repeat of 2016 day 6 for anyone interested - it's kinda like Eric just took both parts from that day, and changed them a little. I used nested for loops to find the most common item for each bit in each string. Another trick you may not know is int(var, 2) which converts a string in binary to a decimal integer - perfect for today. Another cool thing to notice is that it asks you to get both the max and min occurrence of numbers in any given column to figure out both the gamma and epsilon rate. However, you can just work out one, and invert the bits because there are only 2 things it could be (1 or 0). Even better, you could recognise that a binary number plus its inverted counterpart is equal to the max number it could be, assuming the bit-count is the same. For instance;
Let's take a 3-bit number as opposed to the 12-bit ones supplied in the puzzle.
101 = 5
Now let's invert the bits;
010 = 2
If we 'add' both numbers together, we get:
111 = 7
So we can see that a binary number plus its inverted form is just a series of 1s. As the number of bits per number in our input is 12, we can do (2**12)-1 to find the maximum representable number (something you learn in year 8 comp sci). This meant I calculated the answer by just multiplying one by the inverse of the other without ever really simulating it!
Today had a couple of algorithmic tricks, but it was more a matter of doing part 1 fast and not making easy errors - there was a lot to keep track of!
Part 2, on the other hand, was annoying! The puzzle was a bit wordy with only minor - yet specific - alterations to part 1. Not much to say here other than, if you are stuck, to ensure your part 1 solution is good and relatively efficient before thinking about your part 2. Think carefully about logic errors here ;) Don't be afraid to make some copies of variables if you need to use them several times, heck, just copy entire chunks of code if you must.....
I predict Day 4 will be an easier ride into the weekend, whilst Day 5 will be a brain-racking challenge (hopefully not recursion)!