aboutsummaryrefslogtreecommitdiff
path: root/day16/part1
blob: be38c2e1deacff3936e70d6d38c4f81d4ee3eaae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/env ruby

input = gets.chomp.split(',')

line = %w( a b c d e f g h i j k l m n o p )

input.each do |istr|
  case istr[0]
  when 's'
    n = istr[1..-1].to_i
    line = line[-n..-1] + line[0..-n-1]
  when 'x'
    ns = istr[1..-1].split('/').map(&:to_i)
    t = line[ns[0]]
    line[ns[0]] = line[ns[1]]
    line[ns[1]] = t
  when 'p'
    ps = istr[1..-1].split('/')
    i0 = line.index(ps[0])
    i1 = line.index(ps[1])
    line[i0] = ps[1]
    line[i1] = ps[0]
  end
end

puts line.join