Created
February 27, 2018 22:27
-
-
Save bdkosher/1a69b90c7d717b17a489f59e650fd17d to your computer and use it in GitHub Desktop.
For naming Babo's boat
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
def neededChars = 'acdejklmps'.chars as List | |
def words = [] | |
new File(/C:\dev\temp\words\words_boat.txt/).each { word -> | |
words << word | |
} | |
int wordCount = words.size() | |
def r = new Random() | |
(1..50).each { | |
def nameParts = [] | |
while (nameParts.isEmpty() || !(nameParts.join().chars as List).containsAll(neededChars)) { | |
nameParts << words[r.nextInt(wordCount)] | |
if (nameParts.size() > 3) nameParts.clear() | |
} | |
println nameParts.join(' ') | |
} |
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
def good = 'acdejklmps' | |
def illegal = 'abcdefghijklmnopqrstuvwxyz' | |
good.each { illegal -= it } | |
def goodWords = [] | |
// download a dictonary, e.g. https://github.com/dwyl/english-words/blob/master/words.txt, and save to file | |
new File(/C:\dev\temp\words\words_alpha.txt/).eachLine { word -> | |
if (!illegal.find { word.chars.contains(it) } | |
&& word.length() > 2 | |
&& !(word.chars as List).intersect('aeiouy'.chars as List).isEmpty()) { | |
goodWords << word | |
} | |
} | |
def out = new File(/C:\dev\temp\words\words_boat.txt/) | |
goodWords.each { out << "$it\n" } | |
println goodWords.size() // just for echoing out the number of words found |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment