-
Notifications
You must be signed in to change notification settings - Fork 0
/
absurdleLikely.py
64 lines (56 loc) · 1.91 KB
/
absurdleLikely.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
import multiprocessing
import psutil
from absurdle import playAbsurdle, GREENSQUARE
def chunks(l, n):
""" Yield n successive chunks from l.
"""
newn = int(len(l) / n)
for i in range(0, n-1):
yield l[i*newn:i*newn+newn]
yield l[n*newn-newn:]
def solve(wordBank: set, maxDepth, depth, depth0Results, realWordBank = set()) -> list:
if depth == 0:
depth0SolvedWords = 0
# base case
if len(wordBank) == 1:
return (0, list(wordBank))
# max depth protection
if depth >= maxDepth:
return (-1, [])
# best variables
shortestMoveCount = maxDepth
shortestWords = []
for guess in wordBank:
# main function invocation
feedback, newWordBank, error = playAbsurdle(guess, realWordBank if depth == 0 else wordBank)
# all correct base case?
if feedback == GREENSQUARE * 5:
return (0, [guess])
newMoveCount, newWords = solve(newWordBank, depth + shortestMoveCount, depth + 1, depth0Results)
if depth == 0:
depth0SolvedWords += 1
depth0Results.append(newMoveCount + 1)
print(f"process id: {psutil.Process().pid} depth 0 solved word: {guess} solved total {depth0SolvedWords}")
if newMoveCount == -1: continue
if newMoveCount < shortestMoveCount - 1:
shortestMoveCount = newMoveCount + 1
shortestWords = [guess] + newWords
return (shortestMoveCount, shortestWords)
MULTITHREAD = True
if __name__ == "__main__":
mystery_words_file = open("absurdle_mystery_words.txt", "r")
mysteryWordBank = mystery_words_file.read().splitlines()
if MULTITHREAD:
pool = multiprocessing.Pool(processes=7)
args = []
depth0Results = multiprocessing.Manager().list()
for subWordBank in chunks(mysteryWordBank[0:294], 7):
args.append((subWordBank, float("inf"), 0, depth0Results, set(mysteryWordBank)))
results = pool.starmap(solve, args)
else:
results = []
# logging results
print(results)
resultsFile = open("results.txt", "w")
resultsFile.write(str(results) + "\n" + str(depth0Results))
resultsFile.close()