solved part 1
parent
574ad7bff2
commit
2330820811
|
@ -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]
|
Loading…
Reference in New Issue