Skip to content

Instantly share code, notes, and snippets.

@nsmaciej
Created May 15, 2015 19:06
Show Gist options
  • Save nsmaciej/33911f952f4b30442169 to your computer and use it in GitHub Desktop.
Save nsmaciej/33911f952f4b30442169 to your computer and use it in GitHub Desktop.
Finding Maciej numbers
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