Created
November 12, 2012 07:09
-
-
Save ox/4057917 to your computer and use it in GitHub Desktop.
Math-y challenge from http://www.zerocater.com/challenge/, find length of sequence of primes where the sum of the N-1 elements is divisible by the Nth element.
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
require 'prime' | |
prime_tester = Prime.instance | |
n = 3 | |
sum = 2 | |
len = 1 | |
loop do | |
if prime_tester.prime? n | |
len = len + 1 | |
if sum % n == 0 and len > (ARGV[0].to_i || 3) | |
break | |
else | |
sum = sum + n | |
end | |
end | |
n = n + 1 | |
end | |
# p nums.reduce(:+) | |
# p nums | |
p len |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment