Advertisement
Guest User

munchausen

a guest
Oct 29th, 2020
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {-# LANGUAGE NumericUnderscores #-}
  2.  
  3. import Data.Array.Unboxed
  4.  
  5. cache :: UArray Int Int
  6. cache = listArray (0, 9) $ 0:[i^i | i <- [1..9]]
  7.  
  8. recourse :: (Int -> Int) -> (Int, Int) -> Int
  9. recourse f (q, r) = cache ! r + f q
  10.  
  11. calc :: Int -> Int
  12. calc n
  13.   | n > 0 = recourse calc $ n `quotRem` 10
  14.   | otherwise = 0
  15.  
  16. isMunchausen :: Int -> Bool
  17. isMunchausen n = (calc n) == n
  18.  
  19. main = do
  20.   mapM_ print $ filter (\i -> isMunchausen i) [0 .. 440_000_000]
  21.   return 0
  22.  
  23.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement