-
Notifications
You must be signed in to change notification settings - Fork 0
/
findsplit.py
44 lines (33 loc) · 959 Bytes
/
findsplit.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
import sys
import enchant
d = enchant.Dict("en_US")
def find_possibilities(string):
possibilities = []
for n in range(2, len(string) + 1):
possibility = string[:n]
if d.check(possibility):
possibilities.append(possibility)
print(possibilities)
return possibilities
def find_score(split):
total = 0
for word in split:
total += get_score(word)
return total
def get_score(string):
return len(string)**2
def find_split(string, score):
if string == "":
return score
possibilities = find_possibilities(string)
minimum = sys.maxint
for possibility in possibilities:
poss_score = get_score(possibility)
poss_score = find_split(string[len(possibility):], poss_score + score)
minimum = min(poss_score, minimum)
return minimum
def main():
sentence = raw_input()
print(find_split(sentence, 0))
if __name__ == "__main__":
main()