Advent of Code: Day 18
Like a GIF For Your Yard

First puzzle

This puzzle is an implementation of Conway’s Game of Life but with lights. Our puzzle input is a 100 x 100 light grid where the # means on and “.” means off. We need to “animate” the lights. That means we need to calculate the next light state based on the previous state using the following rules:

The puzzle solution is to find how many lights are on after 100 iterations.

First some, input parsing:

To calculate the next state of lights we can fold the initial state applying the rules to calculate it as many times as the iteration number (100). When we have the final state, we can flatten and sum the lights to get to how many lights are on:

Second puzzle

For the second puzzle, there is an additional rule:

We can proceed with the same approach, but changing the folding binary function to keep the corners on all the time:

You can find this code along with my input and puzzle answers at here.

*****
Written by Darien Martinez on 18 March 2016