36 lines
624 B
Ruby
36 lines
624 B
Ruby
|
#!/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(:*)
|