Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def dupe_check(true_array):
- number_list = []
- for current_list in true_array:
- for j in current_list:
- number_list.append(j)
- number_list.sort()
- return number_list == range(1,10)
- def magic_square(true_array):
- if not dupe_check(true_array):
- return False
- iSize = len(true_array[0])
- sum_list = []
- #Vertical:
- for col in range(iSize):
- sum_list.append(sum(row[col] for row in true_array))
- #Horizontal
- sum_list.extend([sum (lines) for lines in true_array])
- #Diagonals
- dlResult = 0
- for i in range(0,iSize):
- dlResult +=true_array[i][i]
- sum_list.append(dlResult)
- drResult = 0
- for i in range(iSize-1,-1,-1):
- drResult +=true_array[i][i]
- sum_list.append(drResult)
- if len(set(sum_list))>1:
- return False
- return True
- a = [[2, 7, 6], [9, 5,1 ], [4, 3, 8]]
- b = [[4, 9, 2], [3, 5, 7], [8, 1, 6]]
- print dupe_check(a) # True
- print magic_square(a) # True
- print "and now b"
- print dupe_check(b) # True
- print magic_square(b) # True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement