Newer posts are loading.
You are at the newest post.
Click here to check if anything new just came in.
Click here to check if anything new just came in.
November 05 2008
Groovy Fibber
So, here's a (rather) simple Fibonacci.groovy:
Now, e.g., this shell input:
:-)
Update: Here's how you could do this with Helma NG.
/**
* Calculating and printing out a
* certain amount of Fibonacci numbers.
*/
class Fibber {
BigInteger current, next, newCurrent
// does the actual job:
def calcAndPrint(numberOf) {
current = 1; next = 1
numberOf.times {
print "$current "
newCurrent = next
next += current
current = newCurrent
}; println ''
}
}
try {
def amount = args[0].toInteger()
new Fibber().calcAndPrint(amount)
} catch (e) {
println 'usage: groovy Fibonacci.groovy <amountNumber>'
}
Now, e.g., this shell input:
$ groovy Fibonacci.groovy 13results in this output:
1 1 2 3 5 8 13 21 34 55 89 144 233
:-)
Update: Here's how you could do this with Helma NG.
