AoC 2017 Day 21: Fractal Expander

Source: Fractal Art

Part 1: Start with an input image made of . and # pixels. For n iterations, break the image into blocks:

  • If the current size is even, break the image into 2x2 chunks and replace each with a 3x3 chunk
  • If the current size is odd, break the image into 3x3 chunks and replace each with a 4x4 chunk

The replacement rules will be specified in the following format (example is a 3x3 -> 4x4 rule):

.#./..#/### => #..#/..../..../#..#  

In that example, replace this:

.#.
..#
###

With this:

#..#
....
....
#..#

Any rotation or reflection of a chunk can be used to match the input of a replacement rule.

After n = 18 iterations, how many # pixels are there?

read more...


AoC 2017 Day 18: Duetvm

Source: Duet

Part 1: Create a virtual machine with the following instruction set:

  • snd X plays a sound with a frequency equal to the value of X
  • set X Y sets register X to Y
  • add X Y set register X to X + Y
  • mul X Y sets register X to X * Y
  • mod X Y sets register X to X mod Y
  • rcv X recovers the frequency of the last sound played, if X is not zero
  • jgz X Y jumps with an offset of the value of Y, iff X is greater than zero

In most cases, X and Y can be either an integer value or a register.

What is the value recovered by rcv the first time X is non-zero?

read more...


Visualizing the Monkey Grid

I’m a bit behind the times, but this post from Programming Praxis intrigued me enough that I kept it in my todo list for rather a while. So let’s get around to it.

I’ll just copy the description straight from the Programming Praxis website (although there are at least two previous version:[1][2]):

There is a monkey which can walk around on a planar grid. The monkey can move one space at a time left, right, up or down. That is, from (x, y) the monkey can go to (x+1, y), (x-1, y), (x, y+1), and (x, y-1). Points where the sum of the digits of the absolute value of the x coordinate plus the sum of the digits of the absolute value of the y coordinate are lesser than or equal to 19 are accessible to the monkey. For example, the point (59, 79) is inaccessible because 5 + 9 + 7 + 9 = 30, which is greater than 19. Another example: the point (-5, -7) is accessible because abs(-5) + abs(-7) = 5 + 7 = 12, which is less than 19. How many points can the monkey access if it starts at (0, 0), including (0, 0) itself?

read more...