Last active
October 23, 2017 22:30
-
-
Save chsanch/96cd86e0f369a8f59a4b7a7608d49fe9 to your computer and use it in GitHub Desktop.
Read a file, and obtain all the words that match a letter combinations list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use v6; | |
my %words{Str}; | |
%words.push: ( $_.comb.sort.join => $_ ) for "lemario-general-del-espanol.txt".IO.lines; | |
my @letters = 'o','p','d','e','t','o','r'; | |
# get words for the combinations of different lengths of combinations | |
my %possible_answers{Int}; | |
%possible_answers.push: ( $_.chars => %words{$_} ) for @letters.combinations(3..7).map(*.sort.join).grep({ %words{$_} }); | |
say %possible_answers; | |
# Python: | |
from itertools import combinations | |
from collections import defaultdict | |
letters = ['o','p','d','e','t','o','r'] | |
words = defaultdict(list) | |
with open("lemario-general-del-espanol.txt") as f: | |
for word in f.readlines(): | |
words["".join(sorted(word.strip()))].append(word.strip()) | |
possible_answers = {i : [words["".join(sorted(c))] for c in combinations(letters, i) if "".join(sorted(c)) in words] | |
for i in range(7, 2, -1)} | |
print(possible_answers) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://chsanch.info/lemario-general-del-espanol.txt