Code for the Advent of Code event
aoc
advent-of-code
1import floor from math
2
3cache = {}
4
5init_houses = (max, mod = 10, max_deliveries = -1) ->
6 cache = {}
7
8 for elf = 1, max
9 deliveries = 0
10 for house = elf, max, elf
11 cache[house] = 0 unless cache[house]
12 cache[house] += elf * mod
13 deliveries += 1
14 break if deliveries >= max_deliveries and max_deliveries != -1
15
16get_lowest = (target, mod = 10, max_per_elf = -1) ->
17 max_house = floor target / 10
18
19 init_houses max_house, mod, max_per_elf
20
21 house = 1
22
23 while cache[house] < target do house += 1
24
25 house
26
27{ :get_lowest }