Created
March 14, 2025 01:50
-
-
Save wilhelmklopp/7a03b1515eab051d3b462006407b1c31 to your computer and use it in GitHub Desktop.
kolo demo examples
This file contains hidden or 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
# type: ignore | |
from functools import cache | |
import kolo | |
# @cache | |
def fib(x): | |
if x == 0: | |
return 0 | |
if x == 1: | |
return 1 | |
result = fib(x - 1) + fib(x - 2) | |
print(x, result) | |
return result | |
def A(m, n, s="% s"): | |
if m == 0: | |
return n + 1 | |
if n == 0: | |
return A(m - 1, 1, s) | |
n2 = A(m, n - 1, s % ("A(% d, %% s)" % (m - 1))) | |
return A(m - 1, n2, s) | |
if __name__ == "__main__": | |
# print(fib(10)) | |
with kolo.enabled(): | |
fib(5) | |
with kolo.enabled(): | |
fib(10) | |
# A(3, 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment