Skip to content

Instantly share code, notes, and snippets.

@antsmartian
Created February 12, 2012 01:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antsmartian/1805737 to your computer and use it in GitHub Desktop.
Save antsmartian/1805737 to your computer and use it in GitHub Desktop.
Spell Checker in Groovy :)
//a book keep!
def a = ["grails","griffon","gradle","groovy"]
//user sentence
def sentence = "gralis grfifon grovoy gralde"
def split = sentence.split(' ')
def bool = false
split.each {
i = 0
def temp = []
temp << it.split{it=""}
def word = temp[i].flatten()
def p = word.permutations()
if(word.join() in a)
{
print it + " "
bool = true
}
else
bool = false
check(bool,p,a)
i++;
}
def check(def bool,def p,def a)
{
if(bool == false) {
p.any {
if(it.flatten().join() in a)
{
print it.join() + " "
return
}
}
}
}
println ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment