[2022][ruby][5.x]
change uxuzyutvsxmzqnrrsokpzywqvoupvzlk
commit c47fb74089313b02536488fb2c458daf351785cf
author Alpha Chen <alpha@kejadlen.dev>
date
parent moxstums
diff --git a/2022/ruby/day_05.rb b/2022/ruby/day_05.rb
new file mode 100644
index 0000000..0f7c927
--- /dev/null
+++ b/2022/ruby/day_05.rb
@@ -0,0 +1,18 @@
+setup, moves = ARGF.read.split("\n\n")
+
+setup = setup
+  .lines(chomp: true)
+  .map(&:chars)
+  .transpose
+  .select { _1.last =~ /\d/ }
+  .map { _1[0..-2].join.strip.chars }
+
+moves = moves.scan(/move (\d+) from (\d+) to (\d+)/).map { _1.map(&:to_i) }
+moves.each do |n,from,to|
+  # n.times {
+  #   setup[to-1].unshift(setup[from-1].shift)
+  # }
+  setup[to-1].unshift(*setup[from-1].shift(n))
+end
+
+p setup.map(&:first).join