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