-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolver.py
44 lines (33 loc) · 967 Bytes
/
solver.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
# imports
import json
# files
database = open("database.json", "r")
database_dict = json.load(database)
# char dict
sample_dict = dict()
for ascii_digit in range(97, 123):
sample_dict[chr(ascii_digit)] = 0
# count chars
def count(string):
return_dict = sample_dict.copy()
for char in string:
return_dict[char] += 1
return return_dict
# compare counts
def same_count(one, two):
for ascii_digit in range(97, 123):
if one[chr(ascii_digit)] != two[chr(ascii_digit)]:
# print(one[chr(ascii_digit)], two[chr(ascii_digit)])
return False
return True
# solve scramble
def solve_scramble(scramble):
scramble = scramble.strip()
scramble_count = count(scramble)
length = str(len(scramble))
solutions = []
for word in database_dict[length]:
word_count = count(word)
if same_count(scramble_count, word_count):
solutions.append(word)
return solutions