Adopted new convention from template
This commit is contained in:
parent
787c771162
commit
5f36185d59
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python
|
||||||
"""
|
"""
|
||||||
Created on 09 Oct 2021
|
Created on 09 Oct 2021
|
||||||
|
|
||||||
@ -10,6 +10,7 @@ https://projecteuler.net/problem=57
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from fractions import Fraction
|
from fractions import Fraction
|
||||||
|
|
||||||
from utils import timeit
|
from utils import timeit
|
||||||
|
|
||||||
|
|
||||||
@ -21,7 +22,7 @@ def compute():
|
|||||||
|
|
||||||
By expanding this for the first four iterations, we get:
|
By expanding this for the first four iterations, we get:
|
||||||
|
|
||||||
1 + 1/2 = 3/2 = 1.5
|
1 + 1/2 = 3/2 = 1.5
|
||||||
1 + 1/2+1/2 = 7/5 = 1.4
|
1 + 1/2+1/2 = 7/5 = 1.4
|
||||||
1 + 1/2+1/2+1/2 = 17/12 = 1.41666...
|
1 + 1/2+1/2+1/2 = 17/12 = 1.41666...
|
||||||
1 + 1/2+1/2+1/2+1/2 = 41/29 = 1.41379...
|
1 + 1/2+1/2+1/2+1/2 = 41/29 = 1.41379...
|
||||||
@ -36,7 +37,7 @@ def compute():
|
|||||||
|
|
||||||
ans = 0
|
ans = 0
|
||||||
f = Fraction(1, 2)
|
f = Fraction(1, 2)
|
||||||
for i in range(1000):
|
for _ in range(1000):
|
||||||
f = 1 / (2 + f)
|
f = 1 / (2 + f)
|
||||||
result = 1 + f
|
result = 1 + f
|
||||||
if len(str(result.numerator)) > len(str(result.denominator)):
|
if len(str(result.numerator)) > len(str(result.denominator)):
|
||||||
@ -46,5 +47,4 @@ def compute():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
print(f"Result for Problem 57 is {compute()}")
|
||||||
print(f"Result for Problem 57: {compute()}")
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user