Created
November 4, 2015 10:05
-
-
Save FredrikAugust/5cb5801e26030f69903e to your computer and use it in GitHub Desktop.
Red Squiggle
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
accomodate | |
acknowlegement | |
arguemint | |
comitmment | |
deductabel | |
depindant | |
existanse | |
forworde | |
herrass | |
inadvartent | |
judgemant | |
ocurrance | |
parogative | |
suparseed |
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
# import all words from a dict on my computer | |
words = readall(open("/usr/share/dict/words")) | |
# get the input from a text file and remove excess whitespace | |
input = [strip(x) for x in split(readall(open("input.txt")), "\n")] | |
# remove empty entries | |
for i=1:length(input) | |
if input[i] == "" | |
splice!(input, i) | |
end | |
end | |
# iterate over input-words | |
for word in input | |
println(">> $word") | |
correct_word_part = ASCIIString | |
# check in full word exists already | |
if in(word, split(words, "\n")) | |
println(word) | |
else | |
println("> Look for correct word-part") | |
search_result = UnitRange | |
# iterate down the word backwards | |
for i=length(word):-1:1 | |
# index result | |
search_result = search(words, "$(word[1:i])") | |
# print a "cursor" that moves down the word ("|") | |
println("$(word[1:i])|$(word[i+1:end])") | |
# check if new substring exists | |
if search_result != 0:-1 | |
# assign correct part | |
correct_word_part = word[1:i] | |
# print the word that "works"<"rest of the word" | |
println("$correct_word_part<$(word[i+1:end])") | |
break | |
elseif i == 1 | |
# print the word< | |
println("$word<") | |
end | |
end | |
# will hold the alternatives | |
alternatives = UTF8String[] | |
println("\n> Looking for alternatives") | |
if search_result == 0:-1 | |
println("No alternatives found") | |
else | |
while search_result != 0:-1 | |
# find the next \n that marks the end of a word | |
search_end = search(words, "\n", search_result[1]) | |
# add between the \n's | |
push!(alternatives, words[search_result[1]:search_end[1]]) | |
# get a new search result | |
search_result = search(words, correct_word_part, search_end[1]) | |
end | |
# remove the newlines and join with a ", " | |
alternatives = join([replace(x, r"[\n]", "") for x in alternatives], ", ") | |
println("Alternatives found: $alternatives") | |
end | |
end | |
println() # newline between words for more pleasant reading | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment