Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@neoneye
Last active November 5, 2020 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neoneye/abf7ccc54321a813f2947247c775f065 to your computer and use it in GitHub Desktop.
Save neoneye/abf7ccc54321a813f2947247c775f065 to your computer and use it in GitHub Desktop.
require 'prime'
PRIMES = Prime.first(1000)
# Kevin Ryde pointed out that A337724 corresponds to this formula, with crazy rounding
# prime(n) - prime(n-2)/2 + prime(n-4)/2^2 - prime(n-6)/2^3 + ...
values = [0, 1]
30.times do |i|
sum = 0
power = 0
sign = 1
j = i
while j >= 0
prime = PRIMES[j]
sum += sign * prime.to_f / (2**power)
power += 1
sign = -sign
j -= 2
end
values << sum.round.to_i
end
p values
# Program output:
# [0, 1, 2, 3, 4, 6, 9, 10, 13, 14, 17, 22, 23, 26, 30, 30, 32, 38, 43, 42, 46, 50, 50, 54, 58, 62, 68, 70, 69, 72, 75, 77]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment