-
-
Save MostAwesomeDude/edb4be55bc5efdc1f2db9a857929bf2d to your computer and use it in GitHub Desktop.
An infinite sequence of rationals which doesn't converge
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
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