Skip to content

Instantly share code, notes, and snippets.

@JCGrant
Last active December 3, 2015 01:55
Show Gist options
  • Save JCGrant/1e1a3e4b41e70cecb0e1 to your computer and use it in GitHub Desktop.
Save JCGrant/1e1a3e4b41e70cecb0e1 to your computer and use it in GitHub Desktop.
Square numbers which remain squares with the last digit removed
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