Last active
June 15, 2021 15:40
-
-
Save mniak/449663657c2ced5682105248ad2c316f to your computer and use it in GitHub Desktop.
Find a good command name
This file contains hidden or 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
fingers = [ 'wsx', 'edc', 'rfv', 'tgb', 'yhn', 'ujm', 'ik', 'ol'] | |
vowels = 'aeiyouw' | |
def pick_all(previous=None): | |
for finger in fingers: | |
if not previous or previous not in finger: | |
yield from finger | |
_pick_all_cache = {} | |
def pick_all_cached(previous=None): | |
global _pick_all_cache | |
if previous in _pick_all_cache: | |
return _pick_all_cache[previous] | |
result = list(pick_all(previous)) | |
_pick_all_cache[previous] = result | |
return result | |
def combinations(length, previous=None): | |
for ch in pick_all_cached(previous): | |
if length == 1: | |
yield ch | |
else: | |
for comb in combinations(length-1, ch): | |
yield ch + comb | |
_combinations_cache = {} | |
def combinations_cached(length, previous=None): | |
global _combinations_cache | |
if previous in _combinations_cache: | |
return _combinations_cache[(length, previous)] | |
result = list(combinations(length, previous)) | |
_combinations_cache[(length, previous)] = result | |
return result | |
def has_vowel(word): | |
for v in vowels: | |
if v in word: | |
return True | |
return False | |
def only_with_vowels(words): | |
for word in words: | |
if has_vowel(word): | |
yield word | |
for size in range(3, 5+1): | |
combs = combinations(size) | |
for comb in only_with_vowels(combs): | |
print(comb) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment