Advent of Code: Day 14
Reindeer Olympics

First puzzle

In this puzzle, we have a reindeer competition. The reindeer that flies the longest distance in the competition time wins. A reindeer can fly for x amount of time and after that, it needs to rest for y amount of time. The example in the puzzle description is as follows:

In a 1000 second competition, Reindeer1 flew 1120 km, and Reindeer2 flew 1056 km. In this case, Reindeer1 wins. The solution to the puzzle is the distance the winning reindeer could fly on a 2503 seconds competition.

First, we need to parse the puzzle input or the reindeer “definition”:

A solution could be to fold a collection of seconds from 1 to competitions seconds on the state of every reindeer. On each one-second iteration, we need to calculate the state of each reindeer. A reindeer could be flying or resting. In addition to that, we need to track how long it was in that state and the flying distance. At the end of the fold, we could just find the maximum distance, and that will be our solution:

Second puzzle

We can reuse a lot from the first puzzle code, but we need to have another function to calculate the reindeer progress and another state adding the score to the mix:

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

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