I study Python and I accidentally got a logical task that I took to decide on Python
The task decided, but the crutch. I feel more correct to solve recursion. In general, tell me a more beautiful solution.
d = '5'
T = '0'
N, A, L, G, E, R, B, O = '-1', '-1', '-1', '-1', '-1', '-1', '-1' , '-1'
Rob = -1.
roberto = 0.
RAN_SET = SET ()
For i in Range (12346789, 98764322):
I_S = STR (I)
For j in i_s:
Ran_Set.add (j)
If Len (RAN_SET) == LEN (I_S) and '5' not in i_s and '0' not in i_s:
N, A, L, G, E, R, B, O = I_S [0], I_S [1], i_s [2], i_s [3], i_s [4], i_s [5], i_s [6] , I_S [7]
don = d + o + n + a + l + d
ger = g + e + r + a + l + d
Rob = R + O + B + E + R + T
roberto = (int (don) + int (ger)
Print (Roberto)
If Roberto == Int (ROB):
Print ()
Print ('Got It!')
Break
RAN_SET = SET ()
p.s. The picture shows the addition of a column, if suddenly someone confuses plus in the middle
Answer 1, Authority 100%
is the easiest to solve a bust in, but not all placement with repetitions, like yours, and all permutations
import itertools
DEF SOLVE (A, B, C, KNOWN):
Letters = SET (A + B + C) - known.keys ()
Digits = Set ('0123456789') - set (known.values ())
For Variant In Itertools.permutations (Digits, Len (Letters)):
Table = DICT (Zip (Letters, Variant), ** Known)
Trans = Str.MakeTrans (Table)
If Int (A.Translate (TRANS)) + int (B.Translate (Trans)) == int (C.Translate (Trans)):
Return Table
Print (Solve ('Donald', 'Herald', 'Robert', {d ':' 5 '}))
{'g': '1', 'l': '8', 'R': '7' , 'H': '6', 'A': '4', 'T': '0', 'E': '9', 'B': '3', 'O': '2', ' D ':' 5 '}