[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
@ -34,4 +36,13 @@ ARGF.read.split("\n").each do |instruction|
raise "invalid instruction: '#{instruction}'" raise "invalid instruction: '#{instruction}'"
end end
end end
puts input input
end
input = 'abcdefgh'.chars
input.permutation.each do |candidate|
if scramble(candidate.join) == 'fbgdceah'
puts candidate.join
exit
end
end

Loading…
Cancel
Save