AI Skill 5 Printout
AI Skill 5 Printout
ipynb - Colab
import itertools
# Split the equation into parts (Left-hand side and right-hand side)
lhs, rhs = substituted_problem.split('=')
lhs_sum = sum(map(int, lhs.split('+')))
rhs_value = int(rhs)
# Ensure that no leading zeros are used for the letters at the start
words = problem.split(' ')
leading_letters = [word[0] for word in words if word[0].isalpha()]
if any(mapping[letter] == 0 for letter in leading_letters):
https://colab.research.google.com/drive/1bZjdMYXiYFoal87uIXW936fELJOThsuB#scrollTo=hsx… 1/3
11/18/24, 5:49 PM Untitled11.ipynb - Colab
continue
if check_solution(problem, mapping):
return mapping
return None
solution = solve_crypto_arithmetic(problem)
if solution:
print("Solution found:")
for letter, digit in solution.items():
print(f"{letter} = {digit}")
else:
print("No solution found.")
if __name__ == "__main__":
main()
https://colab.research.google.com/drive/1bZjdMYXiYFoal87uIXW936fELJOThsuB#scrollTo=hsx… 2/3