Advent of Code: Day 6
Probably a Fire Hazard

First puzzle

In this puzzle, we are going to receive instructions on how to turn on/off lights our 1000x1000 light grid. The question we need to solve is how many lights are on after all the instructions are executed.

Lights are numbered from 0 to 999. The instructions on the input are as follows:

This is the first puzzle where some data structure could be created to model the problem:

We need to execute all the actions on lights. That could be folding the actions on them. The lights could be modeled as a triplet where the first to values are the light coordinates, and the third is the state of the light (1 => on, 0 => off). The execution of the action could be seen as a map from the previous lights acting on the lights based on the action and if a particular light is inside the area where the action should be executed. When we are done with all the actions, we need to sum all the light states to find the solution to this puzzle:

Second puzzle

The second part is just a different execution of the instructions:

The question of the puzzle also change. This time is the total brightness instead of how many lights are on.

In our case, the modeling holds, and we need to change the execution function only:

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

Written by Darien Martinez Torres on 06 March 2016