solved part 1

master^2
Jeff Yates 2020-12-15 08:42:23 -05:00
parent 574ad7bff2
commit 2330820811
1 changed files with 18 additions and 0 deletions

18
day15/solution.rb Executable file
View File

@ -0,0 +1,18 @@
#!/bin/env ruby
require 'pry'
numbers = File.read('./input').split(',')
numbers.map!(&:to_i)
2020.times do |i|
next if i < numbers.size
num = numbers[-1]
prev_turn = numbers[..-2].reverse.find_index(num)
if prev_turn == nil
numbers.push(0)
else
new_num = (i - 1) - (numbers.size - 2 - prev_turn)
numbers.push(new_num)
end
end
puts numbers[-1]