Jump to content

Munchausen numbers: Difference between revisions

→‎{{header|Haskell}}: Further reduced the digitToInt version
(→‎{{header|Haskell}}: Further reduced the digitToInt version)
Line 794:
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 DataControl.CharMonad (digitToIntjoin)
import Data.Char (digitToInt)
 
isMunchausen :: Int -> Bool
isMunchausen n =
let go = (+) . join let(^) v =. digitToInt c
n ==
in (==) <*> foldr go 0 . show
(\c n ->
let v = digitToInt c
in n + v ^ v)
0
(show n)
 
main :: IO ()
main = print $ filter isMunchausen [1 .. 5000]</lang>
 
{{Out}}
<pre>[1,3435]</pre>
9,659

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.