Last active
December 3, 2015 01:55
-
-
Save JCGrant/1e1a3e4b41e70cecb0e1 to your computer and use it in GitHub Desktop.
Square numbers which remain squares with the last digit removed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
isSquare :: Integer -> Bool | |
isSquare x | |
= root ^ 2 == x | |
where | |
root = floor $ sqrt $ fromIntegral x | |
isTruncatedSquare :: Integer -> Bool | |
isTruncatedSquare x | |
| x < 10 = False | |
| otherwise = isSquare $ x `div` 10 | |
isSquareAndTS :: Integer -> Bool | |
isSquareAndTS x | |
= isSquare x && isTruncatedSquare x | |
numbersWhichAreSquaesAndTS :: Integer -> [Integer] | |
numbersWhichAreSquaesAndTS n | |
-- post: returns numbers, up to and including n, which are both | |
-- squares and truncated squares | |
= filter isSquareAndTS [1 .. n] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment