32.py 810 B

123456789101112131415161718192021222324252627282930313233343536
  1. pan = set("123456789")
  2. def isPandigital(n):
  3. """Returns a boolean indicating whether a number is pandigital"""
  4. n = set(str(n))
  5. if n == pan:
  6. return True
  7. else:
  8. return False
  9. def main():
  10. productsList = []
  11. # Covers 2 digits * 3 digits
  12. for i in range(10,99):
  13. for j in range(100,999):
  14. product = i*j
  15. if len(str(product)) == 4:
  16. if isPandigital(str(i) + str(j) + str(product)):
  17. if product not in productsList:
  18. productsList.append(product)
  19. print(i,j,product)
  20. # Covers 1 digit * 4 digits
  21. for i in range(2,9):
  22. for j in range(1000,9999):
  23. product = i*j
  24. if len(str(product)) == 4:
  25. if isPandigital(str(i) + str(j) + str(product)):
  26. if product not in productsList:
  27. productsList.append(product)
  28. print(i,j,product)
  29. return sum(productsList)
  30. print(main())