Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from copy import deepcopy
- def sum_squared(nlist, power):
- mysum = 0
- for x in nlist:
- mysum += x ** power
- return mysum
- def power(x, n, counter_list , solutions_list):
- counter = int(x ** (1/n))
- mysum = sum_squared(counter_list, n)
- if mysum == x:
- solution_list = deepcopy(counter_list)
- return solution_list
- else:
- old_counter = deepcopy(counter_list)
- i = counter
- while len(solutions_list) == 0 and i >= 0 and mysum <= x and len(counter_list) <= x:
- if i == 0 or (counter_list and i not in counter_list and i > max(counter_list)):
- counter_list.append(i)
- solutions_list = power(x, n, counter_list, solutions_list)
- counter_list = deepcopy(old_counter)
- i -= 1
- return solutions_list
- for x in range(20):
- for n in range(5):
- print("x, n", x + 1, n + 1)
- sl = power(x + 1, n + 1, [], [])
- print(sl)
- print(len(sl) - 1)
Advertisement
Add Comment
Please, Sign In to add comment