Last active
November 5, 2020 18:29
-
-
Save neoneye/abf7ccc54321a813f2947247c775f065 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
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