Last active
April 25, 2016 09:36
-
-
Save mame-n/f478e17dcdb0b1db910c87ecc6090b0d to your computer and use it in GitHub Desktop.
This file contains 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
include Math | |
class Integer | |
def prime? | |
return false if self == 0 || self == 1 | |
(2..sqrt(self).to_i).all? { |i| self % i != 0 } | |
end | |
end | |
def prime_cornars( h ) | |
[ h*h-(h-1)*3, h*h-(h-1)*2, h*h-(h-1) ].select { |elem| elem.prime? } | |
end | |
def main( maxh = 100000 ) | |
(1..maxh).inject([0, 1]) do |ratio, n| | |
h = n * 2 + 1 | |
ratio[0] += prime_cornars(h).size | |
ratio[1] += 4 | |
return h if ratio[0] / ratio[1].to_f < 0.1 | |
ratio | |
end | |
end | |
puts main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment