Last active
August 23, 2019 15:05
-
-
Save bashkirtsevich/a7d3d3c61110ac9f10552e389f82bf53 to your computer and use it in GitHub Desktop.
Shit calculations
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
def get_chain_length(data): | |
return max(*reduce(lambda a, i: (max(a[0], a[1]), a[1] + 1 if i > 0 else 0), data, (0, 0))) | |
data = [0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1] | |
print(get_chain_length(data)) | |
def fib(n): | |
return reduce(lambda a, i: (a[1], a[0] + a[1]), range(n), (0, 1))[0] | |
print(fib(9)) | |
from math import sqrt | |
from decimal import * | |
getcontext().prec = 1000 | |
r5 = Decimal('5').sqrt() | |
def fib2(n): | |
return round(((1+r5)**n-(1-r5)**n)/(2**n*r5)) | |
print(fib2(10)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment