So, you just decide that each Integer should have an automatic property of knowing it’s Fibonacci number, well now your wish is granted:
Integer.metaClass.getFibonacci {
fib = delegate
def fibno = 1
while (fib) {
fibno += fibno
fib--
}
return fibno
}
Integer x = 25
println x.fibonacci
I admit this is probably not the most useful additional property one could add to an integer and, of course, it is a function of an integer and not a property, but that was not my point…
Related articles
- Something interesting about Fibonacci numbers (cartesianproduct.wordpress.com)
- Something more on Fibonacci numbers (cartesianproduct.wordpress.com)
- From Irrational to Rational (ubpdqnmathematica.wordpress.com)