http://projecteuler.net/problem=32
全パターンの数式について成立するか判定。
1 #!/usr/bin/env ruby
2
3 require 'set'
4 pand = Set.new
5 (1...10).to_a.permutation do |perm|
6 (2...9).to_a.permutation(2) do |sel|
7 next if (sel[0] > sel[1])
8 a = perm[0...sel[0]].join.to_i
9 b = perm[sel[0]...sel[1]].join.to_i
10 c = perm[sel[1]...10].join.to_i
11 pand << c if (a * b == c)
12 end
13 end
14 p pand.to_a.inject{|acc, n| acc+n}