zvoulgaris

Eureka numbers

Sep 24th, 2019
355
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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
RAW Paste Data