import Control.Monad isSquare a b = rem < 0.00000001 where (int, rem) = properFraction $ sqrt $ fromIntegral $ a + b :: (Int, Double) task nums = do let go prev nums = do a <- nums guard $ isSquare prev a case filter (/=a) nums of [] -> return [a] nums1 -> do as <- go a nums1 return $ a : as a <- nums go a (filter (/=a) nums) main = print $ task [1..17]
Standard input is empty
[[9,7,2,14,11,5,4,12,13,3,6,10,15,1,8,17],[8,1,15,10,6,3,13,12,4,5,11,14,2,7,9,16]]
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!