Reduce the usage of vertical lines - make the expression more horizontally aware.
The Fibonacci sequence using a recursive function with a cache.
def fibonacci(b, cache={}): if b <= 1: return b if b in cache: return cache[b] cache[b] = fibonacci(b-1, cache) + fibonacci(b-2, cache) return cache[b]
def fibonacci(b):if 0 <= b <= 1:- def fibonacci(b, cache={}):
- if b <= 1:
- return b
elif b < 0:return Nonereturn fibonacci(b-1) + fibonacci(b-2)- if b in cache:
- return cache[b]
- cache[b] = fibonacci(b-1, cache) + fibonacci(b-2, cache)
- return cache[b]
# TODO: Replace examples and use TDD development by writing your own tests # These are some of the methods available: # test.expect(boolean, [optional] message) test.assert_equals(fibonacci(8), 21) test.assert_equals(fibonacci(20), 6765) test.assert_equals(fibonacci(25), 75025) test.assert_equals(fibonacci(36), 14930352) test.assert_equals(fibonacci(100), 354224848179261915075) test.assert_equals(fibonacci(500), 139423224561697880139724382870407283950070256587697307264108962948325571622863290691557658876222521294125) # test.assert_not_equals(actual, expected, [optional] message) # You can use Test.describe and Test.it to write BDD style test groupings
- # TODO: Replace examples and use TDD development by writing your own tests
- # These are some of the methods available:
- # test.expect(boolean, [optional] message)
test.assert_equals(fibonacci(8),21 )- test.assert_equals(fibonacci(8), 21)
- test.assert_equals(fibonacci(20), 6765)
- test.assert_equals(fibonacci(25), 75025)
- test.assert_equals(fibonacci(36), 14930352)
- test.assert_equals(fibonacci(100), 354224848179261915075)
- test.assert_equals(fibonacci(500), 139423224561697880139724382870407283950070256587697307264108962948325571622863290691557658876222521294125)
- # test.assert_not_equals(actual, expected, [optional] message)
- # You can use Test.describe and Test.it to write BDD style test groupings