Skip to content

Instantly share code, notes, and snippets.

@neoneye
Created September 23, 2020 21:57
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/ed8f9e0f250d14c97b905178469a65ad to your computer and use it in GitHub Desktop.
Save neoneye/ed8f9e0f250d14c97b905178469a65ad 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 + ...
# What about A337723, does it have a similar formula, with crazy rounding?
# Yes, I think I have found a formula that can do it.
accumulator_a = 0.5
accumulator_b = 1
values = [0, 1]
bias = 0.5
28.times do |i|
sum = 0
prime = PRIMES[i]
if i.even?
accumulator_a = prime - ((bias + accumulator_a) / 2.0)
sum = accumulator_a
else
accumulator_b = prime - ((bias + accumulator_b) / 2.0)
sum = accumulator_b
end
values << sum.round.to_i
end
p values
# Program output:
# [0, 1, 2, 2, 4, 6, 9, 10, 12, 14, 17, 22, 22, 26, 30, 30, 32, 38, 43, 42, 45, 50, 50, 54, 58, 62, 68, 70, 69, 72]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment