Advent of Code: Day 20
Infinite Elves and Infinite Houses

First puzzle

This puzzle is about delivering packages. We need to deliver a certain amount of packages to an infinite houses numbers sequentially starting at 1. We also have infinite mail carriers. Each mail carrier is assigned a set of houses based on its number. Based on the puzzle description:

On each delivery, the mail carrier delivers 10-times-his-number packages. For example, Postman 3 delivers 30 packages to each house he visits while Postman 2 delivers 20 packages each time.

The overall packages delivered to the first 4 houses are as follow:

The puzzle solution is to find the lowest house number that gets as many packages as the puzzle input.

To find the solution, we need to calculate how many packages a house n will receive. Based on the description, some packages a house n will receive is equal to the sum of all the unique factors of n multiplied by 10. For example, House 4 factors: 1, 2 and 4, number of packages = (1 + 2 + 4)*10 = 70. Here is the implementation:

Second puzzle

The second puzzle adds a new rule: The mail carrier should deliver packages to 50 houses max. Also, the number of packages delivered per house changes from 10 to 11. These are not big changes; we need to redefine the function to calculate the number of packages to take into account that only factors less than the number of house should be considered:

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

*****
Written by Darien Martinez Torres on 20 March 2016