Skip to content

Instantly share code, notes, and snippets.

@ox
Created November 12, 2012 07:09
Show Gist options
  • Save ox/4057917 to your computer and use it in GitHub Desktop.
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.
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