Created
October 9, 2020 01:26
-
-
Save augray/3745f0cfb85b73f792bd12e9d0831418 to your computer and use it in GitHub Desktop.
This file contains 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
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