Created
April 7, 2019 21:09
-
-
Save planetis-m/79503c6630dc6e216366650d3df4a762 to your computer and use it in GitHub Desktop.
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
import strutils, algorithm | |
const wordlistFilename = "words.txt" | |
template with(f, fn, actions: untyped): untyped = | |
var f: File | |
if open(f, fn): | |
try: | |
actions | |
finally: | |
close(f) | |
else: | |
quit("cannot open: " & fn) | |
proc loadWords(): seq[string] = | |
echo "Loading word list from file..." | |
result = newSeqOfCap[string](83667) | |
with(inFile, wordlistFilename): | |
for line in lines(inFile): | |
result.add(line.strip().toLowerAscii()) | |
echo " ", result.len, " words loaded." | |
proc main = | |
var wordlist = loadWords() | |
# isValidWord calls binarySearch, so wordList needs to be ordered. | |
sort(wordList) | |
let word = "binary" | |
doassert word in wordList | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment