Skip to content

Instantly share code, notes, and snippets.

@igorvanloo
Created February 21, 2025 04:45
Show Gist options
  • Save igorvanloo/967523e4820f5a17916f3daddae2798f to your computer and use it in GitHub Desktop.
Save igorvanloo/967523e4820f5a17916f3daddae2798f to your computer and use it in GitHub Desktop.
p169
from functools import cache
@cache
def a(n):
if n == 0:
return 0
if n == 1:
return 1
if n % 2 == 0:
return a(n//2)
else:
return a((n - 1)//2) + a((n - 1)//2 + 1)
def f(n):
return a(n + 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment