Given a list of numbers, find all matrices such that each column and row sum up to 264
问题 Let's say I have a list of 16 numbers. With these 16 numbers I can create different 4x4 matrices. I'd like to find all 4x4 matrices where each element in the list is used once, and where the sum of each row and each colum is equal to 264. First I find all combination of elements within the list that sum up to 264 numbers = [11, 16, 18, 19, 61, 66, 68, 69, 81, 86, 88, 89, 91, 96, 98, 99] candidates = [] result = [x for x in itertools.combinations(numbers, 4) if sum(x) == 264] result becomes a