problem92.py 302 B

1234567891011121314151617
  1. #!/usr/bin/env python
  2. def digits(n):
  3. return [n] if n < 10 else digits(n / 10) + [n % 10]
  4. def quad(n):
  5. return n * n
  6. def end(s):
  7. return s if s == 1 or s == 89 else end(sum(map(quad, digits(s))))
  8. count = 0
  9. for n in xrange(1, 10000000):
  10. if end(n) == 89:
  11. count += 1
  12. print count