074 Digit factorial chains.jl 607 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/julia
  2. # Author: Daniel "Trizen" Șuteu
  3. # Date: 16 August 2016
  4. # License: GPLv3
  5. # Website: https://github.com/trizen
  6. # https://projecteuler.net/problem=74
  7. # Runtime: 8.618s
  8. fac = Int64[factorial(i) for i in 0:9]
  9. function f(n::Int64, fac)
  10. seen = Dict{Int64,Bool}(n => true)
  11. while true
  12. m = sum(Int64[fac[i+1] for i in digits(n)])
  13. haskey(seen, m) && break
  14. seen[m] = true
  15. n = m
  16. end
  17. length(seen) == 60
  18. end
  19. function count(limit)
  20. c = 0
  21. for i in 0:limit-1
  22. f(i, fac) && (c += 1)
  23. end
  24. return c
  25. end
  26. println(count(1_000_000))