Untitled

 avatar
unknown
plain_text
2 years ago
648 B
1
Indexable
INITIAL_STACKS = [
  %w(Q F M R L W C V),
  %w(D Q L),
  %w(P S R G W C N B),
  %w(L C D H B Q G),
  %w(V G L F Z S),
  %w(D G N P),
  %w(D Z P V F C W),
  %w(C P D M S),
  %w(Z N W T V M P C),
].freeze

def solve
  stacks_p1 = INITIAL_STACKS.clone.map(&:clone)
  stacks_p2 = INITIAL_STACKS.clone.map(&:clone)
  File.read('day5/input.txt').split("\n").each do
    quantity, from, to = _1.gsub(/[a-z]|/, '').split(' ').map(&:to_i)
    quantity.times { stacks_p1[to - 1].push(stacks_p1[from - 1].pop) }
    stacks_p2[to - 1].push(*stacks_p2[from - 1].pop(quantity))
  end

  p stacks_p1.map(&:last).join(''), stacks_p2.map(&:last).join('')
end

solve
Editor is loading...