Created
February 12, 2012 01:47
-
-
Save antsmartian/1805737 to your computer and use it in GitHub Desktop.
Spell Checker in Groovy :)
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
//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