From 7ced4db4a44712bee1996f80c33653d752b4207c Mon Sep 17 00:00:00 2001 From: Alpha Chen Date: Mon, 19 Dec 2022 21:39:27 -0800 Subject: [PATCH] [2022][ruby][20.x] --- 2022/ruby/day_20.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 2022/ruby/day_20.rb diff --git a/2022/ruby/day_20.rb b/2022/ruby/day_20.rb new file mode 100644 index 0000000..0dbcca7 --- /dev/null +++ b/2022/ruby/day_20.rb @@ -0,0 +1,19 @@ +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) }