2018-03-15 16:24:23 +00:00
|
|
|
|
Advent of Code
|
2016-12-16 22:21:15 +00:00
|
|
|
|
|
|
|
|
|
--- Day 18: Like a GIF For Your Yard ---
|
|
|
|
|
|
2018-03-15 16:24:23 +00:00
|
|
|
|
After the million lights incident, the fire code has gotten stricter: now,
|
|
|
|
|
at most ten thousand lights are allowed. You arrange them in a 100x100 grid.
|
2016-12-16 22:21:15 +00:00
|
|
|
|
|
2018-03-15 16:24:23 +00:00
|
|
|
|
Never one to let you down, Santa again mails you instructions on the ideal
|
|
|
|
|
lighting configuration. With so few lights, he says, you'll have to resort
|
|
|
|
|
to animation.
|
2016-12-16 22:21:15 +00:00
|
|
|
|
|
2018-03-15 16:24:23 +00:00
|
|
|
|
Start by setting your lights to the included initial configuration (your
|
|
|
|
|
puzzle input). A # means "on", and a . means "off".
|
2016-12-16 22:21:15 +00:00
|
|
|
|
|
2018-03-15 16:24:23 +00:00
|
|
|
|
Then, animate your grid in steps, where each step decides the next
|
|
|
|
|
configuration based on the current one. Each light's next state (either on
|
|
|
|
|
or off) depends on its current state and the current states of the eight
|
|
|
|
|
lights adjacent to it (including diagonals). Lights on the edge of the grid
|
|
|
|
|
might have fewer than eight neighbors; the missing ones always count as
|
|
|
|
|
"off".
|
2016-12-16 22:21:15 +00:00
|
|
|
|
|
2018-03-15 16:24:23 +00:00
|
|
|
|
For example, in a simplified 6x6 grid, the light marked A has the neighbors
|
|
|
|
|
numbered 1 through 8, and the light marked B, which is on an edge, only has
|
|
|
|
|
the neighbors marked 1 through 5:
|
2016-12-16 22:21:15 +00:00
|
|
|
|
|
|
|
|
|
1B5...
|
|
|
|
|
234...
|
|
|
|
|
......
|
|
|
|
|
..123.
|
|
|
|
|
..8A4.
|
|
|
|
|
..765.
|
|
|
|
|
|
2018-03-15 16:24:23 +00:00
|
|
|
|
The state a light should have next is based on its current state (on or off)
|
|
|
|
|
plus the number of neighbors that are on:
|
2016-12-16 22:21:15 +00:00
|
|
|
|
|
2018-03-15 16:24:23 +00:00
|
|
|
|
• A light which is on stays on when 2 or 3 neighbors are on, and turns off
|
|
|
|
|
otherwise.
|
2016-12-16 22:21:15 +00:00
|
|
|
|
|
2018-03-15 16:24:23 +00:00
|
|
|
|
• A light which is off turns on if exactly 3 neighbors are on, and stays
|
|
|
|
|
off otherwise.
|
|
|
|
|
|
|
|
|
|
All of the lights update simultaneously; they all consider the same current
|
|
|
|
|
state before moving to the next.
|
2016-12-16 22:21:15 +00:00
|
|
|
|
|
|
|
|
|
Here's a few steps from an example configuration of another 6x6 grid:
|
|
|
|
|
|
|
|
|
|
Initial state:
|
|
|
|
|
.#.#.#
|
|
|
|
|
...##.
|
|
|
|
|
#....#
|
|
|
|
|
..#...
|
|
|
|
|
#.#..#
|
|
|
|
|
####..
|
|
|
|
|
|
|
|
|
|
After 1 step:
|
|
|
|
|
..##..
|
|
|
|
|
..##.#
|
|
|
|
|
...##.
|
|
|
|
|
......
|
|
|
|
|
#.....
|
|
|
|
|
#.##..
|
|
|
|
|
|
|
|
|
|
After 2 steps:
|
|
|
|
|
..###.
|
|
|
|
|
......
|
|
|
|
|
..###.
|
|
|
|
|
......
|
|
|
|
|
.#....
|
|
|
|
|
.#....
|
|
|
|
|
|
|
|
|
|
After 3 steps:
|
|
|
|
|
...#..
|
|
|
|
|
......
|
|
|
|
|
...#..
|
|
|
|
|
..##..
|
|
|
|
|
......
|
|
|
|
|
......
|
|
|
|
|
|
|
|
|
|
After 4 steps:
|
|
|
|
|
......
|
|
|
|
|
......
|
|
|
|
|
..##..
|
|
|
|
|
..##..
|
|
|
|
|
......
|
|
|
|
|
......
|
|
|
|
|
|
|
|
|
|
After 4 steps, this example has four lights on.
|
|
|
|
|
|
2018-03-15 16:24:23 +00:00
|
|
|
|
In your grid of 100x100 lights, given your initial configuration, how many
|
|
|
|
|
lights are on after 100 steps?
|
2016-12-16 22:21:15 +00:00
|
|
|
|
|
|
|
|
|
Your puzzle answer was 814.
|
|
|
|
|
|
|
|
|
|
--- Part Two ---
|
|
|
|
|
|
2018-03-15 16:24:23 +00:00
|
|
|
|
You flip the instructions over; Santa goes on to point out that this is all
|
|
|
|
|
just an implementation of Conway's Game of Life. At least, it was, until you
|
|
|
|
|
notice that something's wrong with the grid of lights you bought: four
|
|
|
|
|
lights, one in each corner, are stuck on and can't be turned off. The
|
|
|
|
|
example above will actually run like this:
|
2016-12-16 22:21:15 +00:00
|
|
|
|
|
|
|
|
|
Initial state:
|
|
|
|
|
##.#.#
|
|
|
|
|
...##.
|
|
|
|
|
#....#
|
|
|
|
|
..#...
|
|
|
|
|
#.#..#
|
|
|
|
|
####.#
|
|
|
|
|
|
|
|
|
|
After 1 step:
|
|
|
|
|
#.##.#
|
|
|
|
|
####.#
|
|
|
|
|
...##.
|
|
|
|
|
......
|
|
|
|
|
#...#.
|
|
|
|
|
#.####
|
|
|
|
|
|
|
|
|
|
After 2 steps:
|
|
|
|
|
#..#.#
|
|
|
|
|
#....#
|
|
|
|
|
.#.##.
|
|
|
|
|
...##.
|
|
|
|
|
.#..##
|
|
|
|
|
##.###
|
|
|
|
|
|
|
|
|
|
After 3 steps:
|
|
|
|
|
#...##
|
|
|
|
|
####.#
|
|
|
|
|
..##.#
|
|
|
|
|
......
|
|
|
|
|
##....
|
|
|
|
|
####.#
|
|
|
|
|
|
|
|
|
|
After 4 steps:
|
|
|
|
|
#.####
|
|
|
|
|
#....#
|
|
|
|
|
...#..
|
|
|
|
|
.##...
|
|
|
|
|
#.....
|
|
|
|
|
#.#..#
|
|
|
|
|
|
|
|
|
|
After 5 steps:
|
|
|
|
|
##.###
|
|
|
|
|
.##..#
|
|
|
|
|
.##...
|
|
|
|
|
.##...
|
|
|
|
|
#.#...
|
|
|
|
|
##...#
|
|
|
|
|
|
|
|
|
|
After 5 steps, this example now has 17 lights on.
|
|
|
|
|
|
2018-03-15 16:24:23 +00:00
|
|
|
|
In your grid of 100x100 lights, given your initial configuration, but with
|
|
|
|
|
the four corners always in the on state, how many lights are on after 100
|
|
|
|
|
steps?
|
2016-12-16 22:21:15 +00:00
|
|
|
|
|
|
|
|
|
Your puzzle answer was 924.
|
|
|
|
|
|
|
|
|
|
Both parts of this puzzle are complete! They provide two gold stars: **
|
|
|
|
|
|
2018-03-15 16:24:23 +00:00
|
|
|
|
At this point, you should return to your advent calendar and try another
|
|
|
|
|
puzzle.
|
2016-12-16 22:21:15 +00:00
|
|
|
|
|
|
|
|
|
If you still want to see it, you can get your puzzle input.
|
|
|
|
|
|
|
|
|
|
References
|
|
|
|
|
|
|
|
|
|
Visible links
|
|
|
|
|
. http://adventofcode.com/
|
|
|
|
|
. http://adventofcode.com/about
|
|
|
|
|
. http://adventofcode.com/stats
|
|
|
|
|
. http://adventofcode.com/leaderboard
|
|
|
|
|
. http://adventofcode.com/settings
|
|
|
|
|
. http://adventofcode.com/auth/logout
|
|
|
|
|
. http://adventofcode.com/day/6
|
|
|
|
|
. https://en.wikipedia.org/wiki/Conway's_Game_of_Life
|
|
|
|
|
. http://adventofcode.com/
|
|
|
|
|
. http://adventofcode.com/day/18/input
|