Advent of Code: Day 3
Perfectly Spherical Houses in a Vacuum

First puzzle

This time, we are helping Santa to deliver presents. The instruction to Santa is string of characters. Each character is a direction to move:

The puzzle is to find how many different houses received, at least, one gift.

First, let us parse the input to pairs of moves:

To calculate the visited houses, we can fold on the moves accumulating every house position. With the collection of houses, we can find the distinct houses, and calculate to size of that collection to find the puzzle answer:

Second puzzle

For the second puzzle, we have two people delivering the gifts. They have the same instructions, but they take turns to follow them. Ex. The first person gets instruction index 1 and the second person index 2. The question continues to be how many houses receive at least one present.

We need to find the moves for each person, calculate their visited houses, concatenate the two collections and find the distinct houses. The size of that collection will be the puzzle answer:

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

Written by Darien Martinez Torres on 03 March 2016