-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·178 lines (135 loc) · 4.38 KB
/
main.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# -*- coding: utf-8 -*-
from array import array
import re
import os
file = open(os.path.abspath("./words_pt-br_five_letters.txt"), 'r')
words = file.readlines()
excluded = []
contains = {}
awnser = {0: '', 1: '', 2: '', 3: '', 4: ''}
exclusiveOne = []
TwoOrMore = []
def checkExcluded(word):
for letter in excluded:
result = word.find(letter)
if (result > -1):
return False
return True
def checkContains(word):
for letter in contains:
if (word.find(letter) == -1):
return False
occurrences = [m.start() for m in re.finditer(letter, word)]
for i in occurrences:
for j in contains[letter]:
if (j == i):
return False
return True
def checkExact(word):
for index in awnser:
if (awnser[index] != ''):
if (awnser[index] != word[index]):
return False
return True
def checkTwoMore(word):
for letter in TwoOrMore:
if (word.count(letter) < 2):
return False
return True
def checkExclusivelyOne(word):
for letter in exclusiveOne:
if (word.count(letter) != 1):
return False
return True
def InsertWord(letters: array, positions: array):
# Letters is an array with the letters of word
# Positions is an array with the position of this letters\
word = {}
for i in range(len(letters)):
letter = letters[i]
position = positions[i]
word[position] = letter
do = True
# Impede de remover letra já inserida
for index in awnser:
if (awnser[index] == letter and position == 0):
do = False
exclusiveOne.append(letter)
for index in contains:
if (index == letter and position == 0):
do = False
if (do):
if (position > 0):
awnser[(position-1)] = letter
if letter in excluded:
excluded.remove(letter)
elif (position < 0):
if (letter in contains):
contains[letter].append((abs(position)-1))
else:
contains[letter] = [(abs(position)-1)]
else:
excluded.append(letter)
for position in word:
letter = word[position]
if (position < 0):
for i in word:
if (letter == word[i] and i > 0):
TwoOrMore.append(letter)
def getInfo():
word = {}
data = input(
"Insira os dados descobertos (Letra, Posicao) (0 para letra invalida): ")
if data == 0:
exit()
dataArray = data.split(" ")
for info in dataArray:
infoArray = info.split(",")
do = True
letter = infoArray[0]
position = int(infoArray[1])
word[position] = letter
# Impede de remover letra já inserida
for index in awnser:
if (awnser[index] == letter and position == 0):
do = False
exclusiveOne.append(letter)
for index in contains:
if (index == letter and position == 0):
do = False
if (do):
if (position > 0):
awnser[(position-1)] = letter
if letter in excluded:
excluded.remove(letter)
elif (position < 0):
if (letter in contains):
contains[letter].append((abs(position)-1))
else:
contains[letter] = [(abs(position)-1)]
else:
excluded.append(letter)
for position in word:
letter = word[position]
if (position < 0):
for i in word:
if (letter == word[i] and i > 0):
TwoOrMore.append(letter)
def mainLoop():
while True:
response = open('res.txt', 'w')
count = 0
getInfo()
for word in words:
if (checkExcluded(word) and checkContains(word) and checkExact(word) and checkExclusivelyOne(word) and checkTwoMore(word)):
response.write(word)
count += 1
print("Quantidade de possiveis respostas:", count)
print(excluded)
print(awnser)
print(contains)
print(exclusiveOne)
print(TwoOrMore)
response.close()
if (__name__ == "__main__"):
mainLoop()