Fibonacci Series in 1-Line PHP / Java Software
No, I am not competing for obfuscated code context. I realized while showing it to someone that Fibonacci series can be written much more succintly using modern programming languages like c, java or php.
Here is the one-line php version:
' ?>
It outputs 100 fibonacci numbers, each in separate line.
Note: It doesn't use a temporary variable as is normal in other implementations. It obviates the need by utilizing the power of expressions. The rest is achieved with a simple for loop.
Here is the same example in Java / JSP.
<% for(double current = 1, last = 0, i = 1;i++ <= 100;) out.println((current = last + (last = current)) + "
"); %>
Note: The double is used because long is unable to display correctly all 100 numbers due to size limitations.
Filed under Headline News, Java Software, PHP, Tech Note |
|
RSS 2.0 |
Trackback this Article
|
Email this Article
You may also like to read |




































May 24th, 2006 at 12:32 am
all the viruses are not dangerous some are operating systems
May 27th, 2006 at 6:40 am
How is it relevant in context?
October 4th, 2006 at 2:12 am
Your php fubonacci script does not work mate
October 4th, 2006 at 5:34 am
Single quotes problem mate. It now works fine.
February 12th, 2008 at 8:12 am
That is not the fibonacci sequence..
June 19th, 2008 at 6:40 am
does anyone know the fibonacci code for this output?
0 1 1 2 3 5 8
i only know this part $limit=7 =( help