-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpermutator.py
88 lines (76 loc) · 1.47 KB
/
permutator.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
def chr_before_wrds(chr, list):
x=[]
for i in list:
x.append(chr+i)
return x
def alph(w):
m =list(w)
m.sort()
return ''.join(m)
def remove_aindexfromb(a,b):
b = list(b)
del b[a]
oy= "".join(b)
return oy
def degn(a):
l=[]
al = alph(a)
n1=-1
for i in al:
n1+=1
m1 = remove_aindexfromb(n1,al)
x1 = m1
x2 = m1[::-1]
f_ = [i+x1, i+x2]
l+=f_
return l
def pr(lis, mark, file):#prints the output
m=0
for i in lis:
m+=1
if i==mark:
file.write(str(m)+' '+i+' <----Over here\n')
else:
file.write(str(m)+' '+i+'\n')
def funcher(func):
def funched(a):
al2 = alph(a)
m=-1
fi = []
for i in al2:
m+=1
x=remove_aindexfromb(m,al2)
l= func(x)
li = chr_before_wrds(i,l)
fi+=li
return fi
return funched
def eliminator(lis):#removes words that repeat, no need to use it if all characters are distinct
d= []
for i in lis:
if i in d:
continue
elif i not in d:
d.append(i)
return d
def dis_check(a):#checks if all characters are distinct or not, so we don't have to use eliminator()
h =[]
for i in a:
if i in h:
t=False
break
else:
h+=[i]
else:
t= True
return t
f = open('words.txt','w')
wrd = input('Enter the word:')
n =len(wrd)
for i in range(4,n+1):
degn = funcher(degn)
if dis_check(wrd):
pr(degn(wrd),wrd, f)
else:
pr(eliminator(degn(wrd)),wrd, f)
print('Done!')