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/2022/ruby/day_20.rb

20 lines
406 B

list = ARGF.read.lines(chomp: true).map(&:to_i)
list = list.map { _1 * 811589153 }
list = list.map.with_index { [_2, _1] }
10.times do
(0...list.size).each do |i|
j = list.index {|ii,_| ii == i }
_, n = list.delete_at(j)
j += n
j %= list.size
list.insert(j, [i, n])
end
end
list = list.map(&:last)
i = list.index(0)
p [1000, 2000, 3000].sum { list.fetch((i + _1) % list.size) }