Skip to content

Instantly share code, notes, and snippets.

@MostAwesomeDude
Last active May 15, 2022 15:44
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 MostAwesomeDude/edb4be55bc5efdc1f2db9a857929bf2d to your computer and use it in GitHub Desktop.
Save MostAwesomeDude/edb4be55bc5efdc1f2db9a857929bf2d to your computer and use it in GitHub Desktop.
An infinite sequence of rationals which doesn't converge
from fractions import Fraction
from math import floor
def fib(i, _l=[0,1]):
while len(_l) <= i: _l.append(_l[-2] + _l[-1])
return _l[i]
def approx(i):
return Fraction(fib(i), fib(i + 1))
def f(j):
rv = Fraction(0, 1)
for i in range(1, j):
rv += approx(i)
if rv >= 1:
rv -= 1
return rv
def asBuckets(f, j, n):
d = 2 ** n
buckets = [0] * d
for i in range(j):
buckets[floor(f(i) * d)] += 1
return buckets
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment