You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
advent-of-code/2017/ruby/day_13.rb

12 lines
329 B

firewall = Hash[ARGF.read.strip.scan(/(\d+): (\d+)/).map {|x| x.map(&:to_i) }]
def caught?(time, range)
(time % (2 * (range - 1))).zero?
end
p firewall.select {|depth, range| caught?(depth, range) }.map {|d,r| d * r }.sum
p (1..Float::INFINITY).find {|delay|
firewall.none? {|depth, range| caught?(delay+depth, range) }
}