diff options
author | Nat Lasseter <Nat Lasseter nathan@bytemark.co.uk> | 2017-12-18 22:33:26 +0000 |
---|---|---|
committer | Nat Lasseter <Nat Lasseter nathan@bytemark.co.uk> | 2017-12-18 22:33:26 +0000 |
commit | a2019b1372bbd485ff36b49456af0189644711ff (patch) | |
tree | 44f98858634f704768f5a8f58e010b16f8bced10 /day16/part1 | |
parent | 999db74bb78ccded11230933ff5d247c51040a29 (diff) |
Day16 Part1
Diffstat (limited to 'day16/part1')
-rwxr-xr-x | day16/part1 | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/day16/part1 b/day16/part1 new file mode 100755 index 0000000..be38c2e --- /dev/null +++ b/day16/part1 @@ -0,0 +1,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 |