Skip to content

Instantly share code, notes, and snippets.

@augray
Created October 9, 2020 01:26
Show Gist options
  • Save augray/3745f0cfb85b73f792bd12e9d0831418 to your computer and use it in GitHub Desktop.
Save augray/3745f0cfb85b73f792bd12e9d0831418 to your computer and use it in GitHub Desktop.
from functools import lru_cache
@lru_cache
def a(n):
import math
def S(m):
return [j * j for j in range(1, int(math.sqrt(m)) + 1)]
if n == 0:
return 0
possible_moves = [n - s for s in S(n)]
if any(a(n - s) % 2 == 0 for s in S(n)):
return min(a(n - s) for s in S(n) if a(n - s) % 2 == 0) + 1
else:
return max(a(n - s) for s in S(n)) + 1
print([a(i) for i in range(20)])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment