Created
May 15, 2015 19:06
-
-
Save nsmaciej/33911f952f4b30442169 to your computer and use it in GitHub Desktop.
Finding Maciej numbers
This file contains hidden or 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
| module Main where | |
| fastlog :: Int -> Int -> Int | |
| fastlog b n | |
| | n < 1 = -1 | |
| | otherwise = 1 + fastlog b (n `div` b) | |
| roundt :: Int -> Int | |
| roundt n = m * (n `div` m) | |
| where m = 10 ^ (fastlog 10 n) | |
| sumt :: Int -> Int | |
| sumt n = (n * n + n) `div` 2 | |
| maciejt :: Int -> Bool | |
| maciejt x = y == roundt y | |
| where y = sumt x | |
| maciej :: [Int] | |
| maciej = filter maciejt [1..] | |
| main :: IO () | |
| main = mapM_ print maciej |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment