# -*- coding: utf-8 -*- # http://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%2035 # # そのまま.. # require 'prime' def circular_prime?(x) a = x.to_s.chars.to_a (1 ... a.size).reduce(true) do |ret, i| ret && Prime.prime?(a.rotate(i).join.to_i) end end puts Prime.each(1000000 - 1).reduce(0) {|count, prime| count + (circular_prime?(prime) ? 1 : 0) }