solved part 2

master
Jeff Yates 2020-12-10 12:08:38 -05:00
parent e60e40ccb2
commit e4657f1f08
1 changed files with 36 additions and 0 deletions

36
day10/solution2.rb Executable file
View File

@ -0,0 +1,36 @@
#!/bin/env ruby
require 'pry'
numbers = File.read('./input').split("\n").map(&:to_i).sort
numbers.prepend(0)
numbers.push(numbers[-1] + 3)
#binding.pry
solution = numbers.map.with_index do |num, i|
next if i == 0
num - numbers[i-1]
end
solution.compact!
count = [0]
count_i = 0
solution.each.with_index do |num, i|
next if i == 0
if num == 3
count_i += 1
count.push(0)
next
end
count[count_i] += 1 if solution[i-1] == 1
end
count.delete(0)
count.map! do |num|
case num
when 1
2
when 2
4
when 3
7
end
end
p count.reduce(:*)