-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsorters.py
144 lines (129 loc) · 5.15 KB
/
sorters.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
def sortgrayyellowgreen(allwords, gray, yellow, green, debug):
if debug:
print("\nModifications Log:")
tempwords = []
for word in allwords:
delword = False
j = 0
for letter in green:
if (letter != word[j]) and (letter != ""):
# print(letter + word[j])
delword = True
if debug:
print("Deleted \"" + word + "\" because it did not contain the green letter \"" + letter + "\".")
j += 1
j = 0
for lettergroup in yellow:
if lettergroup != "":
for letter in lettergroup:
if letter not in word:
delword = True
if debug:
print ("Deleted \"" + word + "\" because it did not contain the yellow letter \"" + letter + "\".")
if (letter == word[j]):
# print(letter + word[j])
delword = True
if debug:
print ("Deleted \"" + word + "\" because it contained the yellow letter \"" + letter + "\" but at the position it was previously at.")
j += 1
for letter in gray:
if (letter in word):
delword = True
if debug:
print("Deleted \"" + word + "\" because it contained the gray letter \"" + letter + "\".")
if not delword:
tempwords.append(word)
return tempwords
def topword(allwords, debug, entry):
temp = []
returnlist = []
vowels = ["a", "e", "i", "o", "u"]
letterrank = []
topletters = []
alphabet = "abcdefghijklmnopqrstuvwxyz"
topscore = 0
with open('commonwords.txt') as cmnwords:
commonwords = cmnwords.readlines()
commonwords = [x.strip().lower() for x in commonwords]
for i in range (0,len(alphabet)):
letterrank.append(0)
for eachword in commonwords:
for eachletter in eachword:
letterrank[alphabet.index(eachletter)] += 1
for i in range (0,26):
topindex = 0
topindexvalue = 0
for j in range (0,26):
if letterrank[j] > topindexvalue:
if alphabet[j] not in topletters:
topindexvalue = letterrank[j]
topindex = j
topletters.append(alphabet[topindex])
common = False
for word in allwords:
if word in commonwords:
common = True
temp.append(word)
if not common:
temp = allwords
elif debug:
print ("\nCommon words: " + str(temp))
if debug:
print("\nSorting words based on vowel counts:")
for word in temp:
tempscore = 0
templetterstore = []
for letter in word:
if (letter in vowels) and (not letter in templetterstore):
tempscore += 1
templetterstore.append(letter)
if tempscore == topscore:
returnlist.append(word)
if debug:
print("Added '" + word + "' to list of top vowel words because it tied for top with " + str(tempscore) + " vowels.")
if tempscore > topscore:
returnlist = [word]
topscore = tempscore
if debug:
print("Reset the top vowel words list because '" + word + "' had " + str(tempscore) + " vowels, more then previously scanned words.")
if debug:
print ("\nWord list sorted based on vowels:")
print (returnlist)
if not returnlist:
return "-----"
else:
if len(returnlist) == 1:
if debug:
print("\nFinal word:")
return returnlist[0]
else:
if debug:
print("\nDuplicate vowel amounts occurred, further narrowing based on letter frequency:")
temp2 = []
topscore = 0
tempscore = 0
templetterstore = []
for word in returnlist:
explination = word + " - "
templetterstore = []
tempscore = 0
for letter in word:
if (letter not in templetterstore) or (entry >= 3):
tempscore = tempscore + (27 - topletters.index(letter))
explination = explination + "added " + letter + " for " + str(27 - topletters.index(letter)) + " points - "
if (letter in templetterstore) and (entry <= 2):
tempscore = tempscore + (0 - topletters.index(letter))
explination = explination + "penalized duplicate " + letter + " for " + str(-27 + topletters.index(letter)) + " points - "
templetterstore.append(letter)
if tempscore > topscore:
topscore = tempscore
temp2 = [word]
if tempscore == topscore:
temp2.append(word)
if debug:
print (explination + "final score: " + str(tempscore))
if debug:
print("\nFinal word:")
return temp2[0]
def rgb_to_hex(rgb):
return '%02x%02x%02x' % rgb