Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import functools
- from collections import defaultdict
- with open("wordlist.txt") as f:
- words = [word.strip() for word in f]
- pangrams = [word for word in words if len(frozenset(word)) == 7]
- def word_score(w):
- if len(w) == 4:
- return 1
- points = len(w)
- if len(set(w)) == 7:
- points += 7
- return points
- subset_score = defaultdict(int)
- for word in words:
- subset_score[frozenset(word)] += word_score(word)
- @functools.cache
- def partial(included, remaining):
- if remaining == "":
- return subset_score[frozenset(included)]
- nextinc = "".join(sorted(included + remaining[0]))
- return partial(included, remaining[1:]) + partial(nextinc, remaining[1:])
- minscores = []
- for pangram in pangrams:
- letters = "".join(sorted(set(pangram)))
- s = 100000000
- for i, let in enumerate(letters):
- s = min(s, partial(letters[i], letters[:i] + letters[i+1:]))
- minscores.append((pangram, s))
- minscores.sort(key=lambda x: x[1])
- print(minscores[:10])
Advertisement
Add Comment
Please, Sign In to add comment