1
0
Fork 0

Start of magic square

main
Bill Ewanick 2023-11-27 16:14:16 -05:00
parent 47b3230d69
commit 6ca4b02c67
1 changed files with 37 additions and 0 deletions

View File

@ -0,0 +1,37 @@
-- https://www.hackerrank.com/challenges/magic-square-forming/problem
module Main where
import Data.List (transpose)
main :: IO ()
main = print "test"
s :: [[Integer]]
s =
[ [5, 3, 4]
, [1, 5, 8]
, [6, 4, 2]
]
-- isMagicSquare n s =
-- all (sum rows == n) &&
-- all (sum cols == n) &&
-- all (sum diag == n)
-- where
-- rows =
get s (x,y) = s !! x !! y
allCoords n = [ (x,y) | x <- [0..n-1], y <- [0..n-1] ]
diagCoords n = [ (x,y) | x <- [0..n-1], y <- [0 ..n-1], x == y ] ++
[ (x,y) | x <- [0..n-1], y <- [n-1, n-2.. 0], x + y == n-1 ]
rowSums :: [[Integer]] -> [Integer]
rowSums = map sum
colSums :: [[Integer]] -> [Integer]
colSums = map sum . transpose
diagSums :: [[Integer]] -> [Integer]
diagSums n = map (\(x,y) -> get n (x,y)) (diagCoords 3)