I have written a program that generates all possible list of first 32 natural numbers and checks if the sum of the adjacent numbers is a perfect square.
The programs has to iterate over 2.3e25 lists(pretty lot of zeroes). whenever I run the program the python kernel crashes. How do I run this program
My code is
from itertools import permutations
import math
def check(nums):
for i in range(len(nums) - 1):
y = nums[i] + nums[i + 1]
z = y ** 0.5
#till here found the square root of the sum of the adjacent numbers in list
if z.is_integer() ==False:
# if there is some two numbers that don't meet condition, function will return False
return False
return nums
x = list(permutations(range(1, 33)))
for q in range(len(x)):
if (check(x[q])):
print(x[q])
break
The answer set I am looking for is [1,8,28,21,4,32,17,19,30,6,3,13,12,24,25,11,5,31,18,7,29,20,16,9,27,22,14,2,23,26,10,15].
Kindly help me out
PS Thanks to members who helped me in writing the function earlier My earlier question