RosettaCodeData/Task/Square-but-not-cube/Haskell/square-but-not-cube-1.hs
2023-07-01 13:44:08 -04:00

26 lines
596 B
Haskell

{-# LANGUAGE TupleSections #-}
import Control.Monad (join)
import Data.List (partition, sortOn)
import Data.Ord (comparing)
------------------- SQUARE BUT NOT CUBE ------------------
isCube :: Int -> Bool
isCube n = n == round (fromIntegral n ** (1 / 3)) ^ 3
both, only :: [Int]
(both, only) = partition isCube $ join (*) <$> [1 ..]
--------------------------- TEST -------------------------
main :: IO ()
main =
(putStrLn . unlines) $
uncurry ((<>) . show)
<$> sortOn
fst
( ((," (also cube)") <$> take 3 both)
<> ((,"") <$> take 30 only)
)