Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. def product(seq):
  2. result = 1
  3. for item in seq:
  4. result *= item
  5. return result
  6.  
  7. def d(x):
  8. while x > 9:
  9. x = product(int(c) for c in str(x))
  10. return x
  11.  
  12. def count_failing_cases(n):
  13. total = 0
  14. for a in range(1, n+1):
  15. for b in range(1, n+1):
  16. for c in range(1, n+1):
  17. if d(a*b) == c and a*b != c:
  18. total += 1
  19. elif d(a*b) != c and a*b == c:
  20. total += 1
  21. return total
  22.  
  23. for n in [4, 5]:
  24. print(f"count_failing_cases({n}) = {count_failing_cases(n)}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement