#!/usr/bin/env python3 """ Puzzle Solver: 2-digit × 3-digit = 5-digit All digits 0-9 used exactly once, first digit of result is 1 """ def has_unique_digits(numbers): """Check if all digits across the numbers are unique (0-9 used exactly once)""" all_digits = [] for num in numbers: all_digits.extend(str(num)) # Check if we have exactly 10 digits (0-9) and all are unique return len(all_digits) == 10 and len(set(all_digits)) == 10 def solve_puzzle(): """Find all solutions to the puzzle""" solutions = [] # Iterate through all 2-digit numbers (10-99) for two_digit in range(10, 100): # Iterate through all 3-digit numbers (100-999) for three_digit in range(100, 1000): product = two_digit * three_digit # Check if product is 5-digit and starts with 1 if 10000 <= product <= 19999: # Check if all digits are unique across all three numbers if has_unique_digits([two_digit, three_digit, product]): solutions.append((two_digit, three_digit, product)) return solutions def main(): print("Solving the puzzle:") print("2-digit × 3-digit = 5-digit") print("All digits 0-9 used exactly once") print("First digit of result is 1") print("-" * 50) solutions = solve_puzzle() if solutions: print(f"Found {len(solutions)} solution(s):") for i, (a, b, c) in enumerate(solutions, 1): print(f"Solution {i}: {a} × {b} = {c}") # Verify the solution print(f" Verification: {a} × {b} = {a * b}") # Show digit usage all_digits = str(a) + str(b) + str(c) used_digits = sorted(set(all_digits)) print(f" Digits used: {used_digits}") print(f" All digits 0-9: {sorted([str(i) for i in range(10)])}") print() else: print("No solutions found!") return solutions if __name__ == "__main__": main()