Skip to content

Instantly share code, notes, and snippets.

  • Save Denenberg/20f319fa8935f4eded6916800b073530 to your computer and use it in GitHub Desktop.
Save Denenberg/20f319fa8935f4eded6916800b073530 to your computer and use it in GitHub Desktop.
Here's a simple program that prints the product of the digits of M^N for all M and N in the given range: Here's an updated version of the program that sorts the results in ascending order:
# Here's a simple program that prints the product
# of the digits of M^N for all M and N in the given range:
# Here's an updated version of the program
# that sorts the results in ascending order:
def product_of_digits(n):
result = 1
while n > 0:
result *= n % 10
n //= 10
return result
results = []
for m in range(2, 10):
for n in range(2, 10):
results.append((m, n, product_of_digits(m**n)))
sorted_results = sorted(results, key=lambda x: x[2])
for res in sorted_results:
print(res[0], res[1], res[2])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment