Created
March 15, 2020 02:56
-
-
Save ahmed4end/6c7e43d525524b49c837ad693370522d to your computer and use it in GitHub Desktop.
Square into Squares. Protect trees!
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
def decompose(n): | |
def rec(n, i): | |
if n<0:return None | |
if n==0:return [] | |
for j in range(i-1,0,-1): | |
hold = rec(n-j**2, j) | |
if hold!=None:return hold+[j] | |
return rec(n**2, n) | |
print(decompose(11)) | |
#>>> [1, 2, 4, 10] | |
#11**2 = 121 = 1**2 + 2**2 + 4**2 + 10**2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment