Collect and sort square numbers in ascending order from three lists: Difference between revisions

Content added Content deleted
No edit summary
Line 276: Line 276:


isPerfectSquare :: Integral a => a -> Bool
isPerfectSquare :: Integral a => a -> Bool
isPerfectSquare n =
isPerfectSquare = (==) <*> ((^ 2) . floor . sqrt . fromIntegral)

let sqr = (floor . sqrt) (fromIntegral n :: Double)
in n == sqr ^ 2


--------------------------- TEST -------------------------
--------------------------- TEST -------------------------
Line 284: Line 283:
main =
main =
print $
print $
squaresSorted
squaresSorted
[ [3, 4, 34, 25, 9, 12, 36, 56, 36]
[ [3, 4, 34, 25, 9, 12, 36, 56, 36],
, [2, 8, 81, 169, 34, 55, 76, 49, 7]
[2, 8, 81, 169, 34, 55, 76, 49, 7],
, [75, 121, 75, 144, 35, 16, 46, 35]
[75, 121, 75, 144, 35, 16, 46, 35]
]</syntaxhighlight>
]</syntaxhighlight>
{{Out}}
{{Out}}
<pre>[4,9,16,25,36,36,49,81,121,144,169]</pre>
<pre>[4,9,16,25,36,36,49,81,121,144,169]</pre>