Skip to content

Instantly share code, notes, and snippets.

@myokoym
Created August 15, 2012 15:19
Show Gist options
  • Save myokoym/3360973 to your computer and use it in GitHub Desktop.
Save myokoym/3360973 to your computer and use it in GitHub Desktop.
1~9までの数値を云々するスクリプト(Problem032)
#! ruby
digits = 9
ans = []
(1..digits).to_a.permutation(digits) do |a|
0.upto(digits - 3) do |i|
i.upto(digits - 3) do |j|
x = a[0..i].join.to_i
y = a[(i + 1)..(j + 1)].join.to_i
z = a[(j + 2)..(digits - 1)].join.to_i
if x * y == z
p "#{x} * #{y} = #{z}"
ans << z
end
end
end
end
p ans.uniq.inject(:+)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment