-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCryptoArithmetic.py
36 lines (36 loc) · 1.05 KB
/
CryptoArithmetic.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import random
op1='TWO'
res='FOUR'
print(" T W O")
print("+")
print(" T W O")
print("----------")
print("F O U R")
print("----------")
flag=0
while flag!=1:
dictt={}
dictt['F']=1
li=[]
li.append(1)
for i in range(len(op1)-1,-1,-1):
if op1[i]!='T':
val=random.randint(2,9)
while val in li:
val=random.randint(2,9)
dictt[op1[i]]=val
dictt[res[i+1]]=(val+val)%10
li.append(val)
li.append((val+val%10))
else:
val=random.randint(5,9)
while val in li:
val=random.randint(5,9)
dictt[op1[i]]=val
li.append(val)
if res[i+1]=='O':
if dictt['O']==val+val or dictt['O']==((val+val)%10):
flag=1
dictt[res[i+1]]=(val+val)%10
li.append((val+val)%10)
print("\nFor above cryptoarithmetic we get following values of the characters to satisfy the constraints:\n",dictt)