Advertisement
zvoulgaris

Eureka numbers

Sep 24th, 2019
1,835
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Julia 0.36 KB | None | 0 0
  1. # Eureka numbers
  2.  
  3. function IsEureka(x::Int64)
  4.     X = split(string(x), "")
  5.     n = length(X)
  6.     s = 0
  7.  
  8.     for p = 1:n
  9.         s += parse(Int64, X[p]) ^ p
  10.         if s > x; return false; end
  11.     end
  12.  
  13.     return s == x
  14. end
  15.  
  16. function main(n::Int64 = 1000000)
  17.     c = 0
  18.  
  19.     for x = 1:n
  20.         if IsEureka(x); c += 1; end
  21.     end
  22.  
  23.     return c
  24. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement