[2016][ruby][21.1]

profile
Alpha Chen 8 years ago
parent 999f1e2f19
commit f95ba52ef9

@ -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

Loading…
Cancel
Save