def solvesCryptarithm(puzzle: str, solution: str) -> bool: """Check if a cryptarithm puzzle is solved correctly. Args: puzzle (str): The cryptarithm puzzle. solution (str): The solution to the puzzle. Returns: bool: True if the puzzle is solved correctly, False otherwise. """ left = puzzle.split(" + ")[0].strip() right = puzzle.split(" + ")[1].split(" = ")[0].strip() result = puzzle.split(" + ")[1].split(" = ")[1].strip() scores = list(solution) for score, letter in enumerate(scores): print(score, letter) left = left.replace(letter, str(score)) right = right.replace(letter, str(score)) result = result.replace(letter, str(score)) print(left, right, result) try: return int(left) + int(right) == int(result) except ValueError: return False print("Testing solvesCryptarithm()...", end="") # 9567 + 1085 = 10652 assert solvesCryptarithm("SEND + MORE = MONEY", "OMY--ENDRS") == True # 201689 + 201689 = 403378 assert solvesCryptarithm("NUMBER + NUMBER = PUZZLE", "UMNZP-BLER") == True # 91542 + 3077542 = 3169084 assert solvesCryptarithm("TILES + PUZZLES = PICTURE", "UISPELCZRT") == True # 8456 + 1074 = 10542 (False) assert solvesCryptarithm("SEND + MORE = MONEY", "OMY-ENDRS") == False # 9567 + 1085 = 1062 (False) assert solvesCryptarithm("SEND + MORE = MONY", "OMY--ENDRS") == False # No S in solution assert solvesCryptarithm("SEND + MORE = MONEY", "OMY--ENDR-") == False print("Passed!")