krkr
2/24/2012 - 10:17 PM

devoxxfr codestory #1

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
}