Home python solve the logic Task with Python

# solve the logic Task with Python

Author

Date

Category

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:
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 , I_S , i_s , i_s , i_s , i_s , i_s  , I_S 
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

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 '}
``````

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.