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/2020/ruby/day_10.rb

17 lines
373 B

adapters = ARGF.read.scan(/\d+/).map(&:to_i)
outlet = 0
device = adapters.max + 3
dist = (adapters + [outlet, device]).sort.each_cons(2).map {|a,b| b - a }
# part 1
# tally = dist.tally
# p dist[1] * dist[3]
p dist
.slice_when {|a,b| a != b }
.select {|run| run.first == 1 }
.map {|run| { 1 => 1, 2 => 2, 3 => 4, 4 => 7 }.fetch(run.size) }
.inject {|a,b| a*b }