Here is the output that I get, It should be converting to Roman Numerals - the following - 3569 and 1234
Number: 3569 1000: III 100: V 10: VI 1: IX
Number: 1234 1000: I 100: II 10: III 1: IV
Here is the code:
def emitRNValue(int quotient, int divisor) {
Map strokes = [1000:['M'],
500:['D'],
100:['C'],
50:['L'],
10:['X'],
5:['V'],
1:['I']]
//def Closure c = { println "$it: ${emitRNValue[qoutient-1]}" }
//(divisor).each (c)
def RNList = ['I','II','III','IV','V','VI','VII','VIII','IX','X']
(divisor).each { println "$it: ${RNList[quotient-1]}"}
//(1..1000).each (c)
// Yes a switch statement works here.
}
def processNumber(int n) {
print "Number: ${n} "
int divisor = 1000
while (n > 0) {
// need integer division here
int quotient = n.intdiv(divisor)
emitRNValue(quotient,divisor)
// println "divisor: ${divisor} quotient ${quotient}"
// now make the number and divisor smaller
n = n - quotient * divisor
divisor = divisor.intdiv(10)
}
println()
}
// body of script
processNumber(3569)
processNumber(1234)