Skip to content

Instantly share code, notes, and snippets.

@thbkrkr
Created February 24, 2012 22:17
Show Gist options
  • Save thbkrkr/1904154 to your computer and use it in GitHub Desktop.
Save thbkrkr/1904154 to your computer and use it in GitHub Desktop.
devoxxfr codestory #1
#!/usr/bin/groovy
map = [ 3:"Foo", 5:"Bar", 7:"Qix" ]
for (i in 1..100) {
r = ""
map.each{ k, v -> r += isDiv(i, k, v) }
map.each{ k, v -> r += has(i, k, v) }
println i + " -> " + ((r == "") ? i : r)
}
def isDiv(n, d, x) {
if (n % d == 0) return x else return ""
}
def has(n, m, x) {
h = ""
for (i in 0..<(n+"").count(m+"")) h += x
return h
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment