Created
January 8, 2018 18:49
-
-
Save mplewis/b4d780e84cfe68e90ed23441d996f5c7 to your computer and use it in GitHub Desktop.
Generate alternating-hand words for easy typing. Dictionary: https://github.com/dwyl/english-words. ruby alt.rb < ~/Downloads/words.txt > alternating.txt; gshuf -n 50 < alternating.txt
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
KEYS_ON_LEFT_HAND = 'qwertasdfgzxcv' | |
def alternating?(iterable) | |
return true if iterable.count < 2 | |
return false if !!iterable[0] == !!iterable[1] | |
alternating? iterable.drop 1 | |
end | |
def key_on_left_hand(word) | |
word.downcase.chars.map { |l| KEYS_ON_LEFT_HAND.include? l } | |
end | |
def alternating_word?(word) | |
alternating? key_on_left_hand word | |
end | |
def long_enough?(word) | |
word.chars.count >= 7 | |
end | |
$stdin.each_line do |word| | |
puts word if long_enough?(word) && alternating_word?(word) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment