Munchausen numbers: Difference between revisions

m
→‎Alternative: minor optimisation on range of tot, now 3*faster
m (→‎{{header|Phix}}: use pygments, handle 0 correctly, check full range, clearer output)
m (→‎Alternative: minor optimisation on range of tot, now 3*faster)
Line 2,099:
string digits = sprint(lo)
sequence res = {}
integer count = 0, l = length(digits)
atom lim = power(10,l), lom = 0
while length(digits)<=maxlen do
count += 1
Line 2,107 ⟶ 2,108:
if d then tot += power(d,d) end if
end for
if tot>=lom and tot<=lim and sort(sprint(tot))=digits then
res &= tot
end if
Line 2,113 ⟶ 2,114:
if j=0 then
digits = repeat('0',length(digits)+1)
lim *= 10
lom = (lom+1)*10-1
exit
elsif digits[j]<'9' then
Line 2,131 ⟶ 2,134:
Munchausen 1..4 digits (999 combinations checked): {1,3435}
All Munchausen, 0..11 digits (352715 combinations): {0,1,3435,438579088}
"10.1s3s"
</pre>
 
7,818

edits