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