Created
November 12, 2015 10:55
-
-
Save bragboy/7529cf5a2014dbd638b1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def find_prime(n) | |
| return false if n <= 1 | |
| 2.upto(Math.sqrt(n).to_i) do |x| | |
| return false if n%x == 0 | |
| end | |
| true | |
| end | |
| large = [] | |
| 1.upto(1000000) { |each_num| large[each_num] = true if find_prime(each_num) } | |
| count = 0 | |
| 1.upto(1000000) do |num| | |
| str = num.to_s | |
| all = (0...str.length).collect { |i| large[((str * 2)[i, str.length]).to_i] ? true : false } | |
| count+=1 if all.inject(0){|b,i| b&&=i} | |
| end | |
| puts "The count of such primes is #{count}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment