-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassoc.py
More file actions
44 lines (30 loc) · 863 Bytes
/
assoc.py
File metadata and controls
44 lines (30 loc) · 863 Bytes
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
37
38
39
40
41
42
43
44
multoperator = {
'a': {'a':'b', 'b':'b', 'c':'a'},
'b': {'a':'c', 'b':'b', 'c':'a'},
'c': {'a':'a', 'b':'c', 'c':'c'},
}
print("The multiplication table:")
print ("LHS\RHS a b c")
for x in ['a', 'b', 'c']:
print(" " + x + ": ", end='')
for y in ['a', 'b', 'c']:
print(multoperator[x][y], end=' ')
print()
dict1 = {}
def solutions(s):
list1 = []
n = len(s)
if n == 2:
answer = (multoperator[s[0]][s[1]])
return answer
if s in dict1:
return dict1[s]
else:
for i in range(1,n):
l = solutions(s[:i])
r = solutions(s[i:])
for x in l:
for y in r:
list1.append(multoperator[x][y])
dict1[s] = set(list1)
return set(list1)