Created
April 10, 2016 14:18
-
-
Save shortsightedsid/22c8cc29a38746af1156b17c282956bc to your computer and use it in GitHub Desktop.
Check if a 2D Vector is a Magic Square
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; Magic Squares - https://www.reddit.com/r/dailyprogrammer/comments/4dccix/20160404_challenge_261_easy_verifying_3x3_magic/ | |
(defun magic-square? (square) | |
(let* ((dims (array-dimensions square)) | |
(size (car dims))) | |
(if (and (typep square 'simple-array) | |
(eq 2 (array-rank square)) | |
(eq size (cadr dims))) | |
(loop for i from 0 below size | |
for j from 0 below size | |
summing (aref square i j) into lr | |
summing (aref square i (- size j 1)) into rl | |
finally (return (eq lr rl))) | |
nil))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment