0hc.net Menu
Home Overview
About Menu
Impressum

Elusive Squarations

Magic square consisting of prime number squares: 11^2 23^2 71^2 61^2 41^2 17^2 43^2 59^2 19^2 Certain numbers when added or substractes give a square number. One example is 10 and 26, added they are 36, substractes 16. Haskell: module Main where main :: IO () main = mapM_ print $ pSN 100 pSN :: Integral a => a -> [(a,a,a,a)] pSN n = [(d,e,d+e,d-e) | a <- map fromIntegral [0..a1], b <- map fromIntegral [0..a2], c <- [a+2*b], f <- [c^2], g <- [a^2], d <- map truncate [(f+g)/2], d <= n, e <- map truncate [(f-g)/2]] where a1 = truncate $ sqrt m a2 = truncate $ sqrt $ m/2 m = fromIntegral n
0hc.net    © 2001-2014 Harald Wolfsgruber