Munchausen numbers: Difference between revisions
Content added Content deleted
m (→{{header|Nim}}) |
(→{{header|Haskell}}: Further reduced the digitToInt version) |
||
Line 794: | Line 794: | ||
The Haskell libraries provide a lot of flexibility – we could also rework the sum, map, and unfold above to a single fold: |
The Haskell libraries provide a lot of flexibility – we could also rework the sum, map, and unfold above to a single fold: |
||
<lang haskell>import |
<lang haskell>import Control.Monad (join) |
||
import Data.Char (digitToInt) |
|||
isMunchausen :: Int -> Bool |
isMunchausen :: Int -> Bool |
||
isMunchausen |
isMunchausen = |
||
⚫ | |||
n == |
|||
foldr |
in (==) <*> foldr go 0 . show |
||
(\c n -> |
|||
⚫ | |||
in n + v ^ v) |
|||
0 |
|||
(show n) |
|||
main :: IO () |
main :: IO () |
||
main = print $ filter isMunchausen [1 .. 5000]</lang> |
main = print $ filter isMunchausen [1 .. 5000]</lang> |
||
{{Out}} |
{{Out}} |
||
<pre>[1,3435]</pre> |
<pre>[1,3435]</pre> |