Last active
December 20, 2015 14:30
-
-
Save wconrad/bfc29afae8b16d8f66ba to your computer and use it in GitHub Desktop.
Advent of Code, Day 20
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# http://adventofcode.com/day/20 | |
input = 34000000 | |
def deliver_presents(num_houses) | |
presents = [0] + [0] * num_houses | |
(1..num_houses).each do |elf| | |
(elf..num_houses).step(elf) do |house_number| | |
presents[house_number] += 10 * elf | |
end | |
end | |
presents | |
end | |
num_houses = 1 | |
presents = nil | |
loop do | |
presents = deliver_presents(num_houses) | |
max_presents = presents.max | |
break if max_presents >= input | |
num_houses *= 10 | |
end | |
i = presents.index do |p| | |
p >= input | |
end | |
puts i |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# http://adventofcode.com/day/20 | |
input = 34000000 | |
def deliver_presents(num_houses) | |
presents = [0] + [0] * num_houses | |
(1..num_houses).each do |elf| | |
visits = 0 | |
(elf..num_houses).step(elf) do |house_number| | |
presents[house_number] += 11 * elf | |
visits += 1 | |
break if visits == 50 | |
end | |
end | |
presents | |
end | |
num_houses = 1 | |
presents = nil | |
loop do | |
presents = deliver_presents(num_houses) | |
max_presents = presents.max | |
break if max_presents >= input | |
num_houses *= 10 | |
end | |
i = presents.index do |p| | |
p >= input | |
end | |
puts i |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment