getPermutationsOfPerfectSquares

Run Settings
LanguagePython
Language Version
Run Command
def getPermutationsOfPerfectSquares(N): ps_array = buildArrayOfPerfectSquares(N) array = ps_array print(array) count = 0 while(array != []): count+=1 array = getPermutations(array, N) return count def buildArrayOfPerfectSquares(N): ps_array = [] for num in range(N): square = (num+1)*(num+1) if square > N: return ps_array else: ps_array.append(square) def getPermutations(array, N): return_array = [] for idx1 in range(len(array)): for idx2 in range(len(array)): sum = array[idx1] + array[idx2] if sum == N: return [] else: # to do: check hash map return_array.append(sum) return return_array sample1 = 13 sample2 = 12 sample3 = 22 assert(getPermutationsOfPerfectSquares(sample1)==2) assert(getPermutationsOfPerfectSquares(sample2)==3) assert(getPermutationsOfPerfectSquares(sample3)==3)
Editor Settings
Theme
Key bindings
Full width
Lines