Task

Show the first   30   positive integers which are squares but not cubes of such integers.

Optionally, show also the first   3   positive integers which are both squares and cubes,   and mark them as such.




{-# 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)
        )