Skip to content

Instantly share code, notes, and snippets.

@crowell
Created December 5, 2022 22:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crowell/71c3101365731065ee4c502b1b97604f to your computer and use it in GitHub Desktop.
Save crowell/71c3101365731065ee4c502b1b97604f to your computer and use it in GitHub Desktop.
x = IO.read(ARGV[0])
y = x.split("\n")[0...8].reverse
arr = [[], [], [], [], [], [], [], [], []]
arr2 = [[], [], [], [], [], [], [], [], []]
y.each do |i|
m = /^.(.)...(.)...(.)...(.)...(.)...(.)...(.)...(.)...(.).$/.match(i)
(1..9).each do |j|
ch = m[j]
unless ch == ' '
arr[j - 1] << ch
arr2[j - 1] << ch
end
end
end
x.split("\n")[10..].each do |i|
m = /^move (\d+) from (\d+) to (\d+)$/.match(i)
cnt = m[1].to_i
from = m[2].to_i
to = m[3].to_i
cnt.times do
tmp = arr[from - 1].pop
arr[to - 1] << tmp
end
tmp = arr2[from - 1].pop(cnt)
arr2[to - 1] << tmp
arr2[to - 1].flatten!
end
s = ""
s2 = ""
arr.each do |a|
s << a[-1]
end
arr2.each do |a|
s2 << a[-1]
end
puts s
puts s2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment