Advertisement
zvoulgaris

Muenchhausen Numbers

Dec 6th, 2019
2,406
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Julia 0.36 KB | None | 0 0
  1. function IsMuenchhausen(x_::Int64)
  2.     x = x_
  3.     s = 0
  4.  
  5.     while x > 10
  6.         x, d = divrem(x, 10)
  7.         if d > 0; s += d ^ d; end
  8.     end
  9.  
  10.     if x > 0; s += x ^ x; end
  11.     return s == x_
  12. end
  13.  
  14. function main(n::Int64 = typemax(Int64))
  15.     z = []
  16.  
  17.     for x = 1:n
  18.         if IsMuenchhausen(x); append!(z, x); end
  19.     end
  20.  
  21.     return z
  22. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement