Munchausen numbers: Difference between revisions

Content added Content deleted
m (→‎{{header|Phix}}: added syntax colouring, made p2js compatible)
Line 2,016: Line 2,016:
1
1
3435</pre>
3435</pre>

=={{header|Picat}}==
<lang Picat>go =>
println([N : N in 1..5000, munchhausen_number(N)]).

munchhausen_number(N) =>
N == sum([T : I in N.to_string(),II = I.to_int(), T = II**II]).</lang>

{{out}}
<pre>[1,3435]</pre>

Testing for a larger interval, 1..500 000 000, requires another approach:
<lang Picat>go2 ?=>
H = [0] ++ [I**I : I in 1..9],
N = 1,
while (N < 500_000_000)
Sum = 0,
NN = N,
Found = true,
while (NN > 0, Found == true)
Sum := Sum + H[1+(NN mod 10)],
if Sum > N then
Found := false
end,
NN := NN div 10
end,
if Sum == N then
println(N)
end,
N := N+1
end,
nl.
</lang>

{{out}}
<pre>1
3435
438579088</pre>



=={{header|PicoLisp}}==
=={{header|PicoLisp}}==