fork download
  1. import Control.Monad
  2.  
  3. isSquare a b = rem < 0.00000001
  4. where (int, rem) = properFraction $ sqrt $ fromIntegral $ a + b :: (Int, Double)
  5.  
  6. task nums = do
  7. let
  8. go prev nums = do
  9. a <- nums
  10. guard $ isSquare prev a
  11. case filter (/=a) nums of
  12. [] -> return [a]
  13. nums1 -> do
  14. as <- go a nums1
  15. return $ a : as
  16. a <- nums
  17. go a (filter (/=a) nums)
  18.  
  19.  
  20.  
  21. main = print $ task [1..17]
  22.  
Success #stdin #stdout 0s 4704KB
stdin
Standard input is empty
stdout
[[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]]