Groovy web console

subscribe to the feed Subscribe
to this
site

bruteMatching

Published 3 months ago by Thor with tags WB
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
def matching(p, S){
    found = false
    (0..(S.size()-p.size())).each{ si ->
        nrMatched=0
        (0..p.size()-1).each{ pi ->
            if(p[pi] == S[si+pi]) nrMatched++
        }
        if(nrMatched == p.size()) found = true
    }
    return found
}

S="All Algorithms are cool."
p="algo"
println(matching(p, S))