|
|
|
@ -1,5 +1,7 @@
|
|
|
|
|
input = 'abcdefgh'
|
|
|
|
|
ARGF.read.split("\n").each do |instruction|
|
|
|
|
|
INSTRUCTIONS = ARGF.read.split("\n")
|
|
|
|
|
|
|
|
|
|
def scramble(input)
|
|
|
|
|
INSTRUCTIONS.each do |instruction|
|
|
|
|
|
case instruction
|
|
|
|
|
when /swap position (\d+) with position (\d+)/
|
|
|
|
|
x = $1.to_i
|
|
|
|
@ -33,5 +35,14 @@ ARGF.read.split("\n").each do |instruction|
|
|
|
|
|
else
|
|
|
|
|
raise "invalid instruction: '#{instruction}'"
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
input
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
input = 'abcdefgh'.chars
|
|
|
|
|
input.permutation.each do |candidate|
|
|
|
|
|
if scramble(candidate.join) == 'fbgdceah'
|
|
|
|
|
puts candidate.join
|
|
|
|
|
exit
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
puts input
|
|
|
|
|