Well, for the second time in my life, I “50 starred” last year’s Advent of Code. By the way, if you’re anyway connected with computing, and haven’t seen Eric Wastl’s keynote presentation Advent of Code, behind the scenes I highly recommended it.

Anyway, it was mainly plain sailing this year, except for 2 stinkers which took me hours to finish – the latter of which I had to look up some hints on reddit before I got it. I thought I’d post my solutions and process (in part of make sure that I understand my solution!)

Day 17

The first one was Day 17. The problem here was that I was getting the right answer in my tests, but the wrong answer with the actual problem. I was convinced it was my maths which was wrong, but it was actually my code – specifically a hidden 32 bit truncation of a 64 bit number. So a bit annoying (no pun intended). It was actually a really nice problem – there was an octal (3 bit) computer which had 3 registers, and a program input of 16 octal numbers. You had to determine the starting value of register A in order for it to generate the program input as it’s output. The way I tackled this was to analyse the program to work out what it was doing, and realise that at the end of each ‘loop’ it left bit shifted A by 3 (aka dividing by 8). This meant that the first number output could only be influenced by the most significant 3 bits of A, i.e. 8 values.

So when you find a value which works for the first program output number, you recurse to the next one, and check it’s 8 values. Of course, you sometimes need to go back up the recursion tree if you can’t find a solution (so ‘1’ in the MSB might give you the right output for the first number, but no value 0-7 in the next 3 bits gives you the second, so you need to go back up to the first one again).

My solution to day 17

The other one was Day 21 – but you’ll have to wait for the next exciting instalment.