(Click image to test code in Java online. No install necessary.) |
The Code 7 Project - Problem 2 - Fibonacci
- Given a number "n", find the "n"-th number in the Fibonacci sequence (0, 1, 1, 2, 3, 5, 8, 13, 21, ...).
- Full problem description is here.
- Description of the Code 7 Project is here.
For this problem (and sub-problems), I've used tutorialspoint.com's online interface to compile and execute the code quickly.
There were 5 sub-problems:
2.a) Just do it.
2.b) No loop. Only constants, no variables.
2.c) No local variables.
2.d) Tail recursion (the function calls itself on the last line in said function).
2.e) No recursion.
Code for all of these can be found under my GitHub repo:
https://github.com/hchiam/code7
Below are individual links to each sub-problem's solution code, and instructions to view/run the code in your web browser:
2.a) Just do it.
http://goo.gl/sxNER4
Click on "problem2a.java" (not .class) to see the code.
Click on "Compile" to make sure the code is set up.
Click on "Execute" to run the code.
2.b) No loop. Only constants, no variables.
http://goo.gl/HS4xhpClick on "problem2b.java" (not .class) to see the code.
Click on "Compile" to make sure the code is set up.
Click on "Execute" to run the code.
2.c) No local variables.
http://goo.gl/diziRiClick on "problem2c.java" (not .class) to see the code.
Click on "Compile" to make sure the code is set up.
Click on "Execute" to run the code.
2.d) Tail recursion (the function calls itself on the last line in said function).
http://goo.gl/6ixNZ8[EDIT: the above link's code isn't true tail recursion, but it does use recursion. Go to this link for the example of true tail recursion: http://goo.gl/ytnRHF]
Click on "problem2d.java" (not .class) to see the code.
Click on "Compile" to make sure the code is set up.
Click on "Execute" to run the code.
2.e) No recursion.
(Same as 2.b).)_________________________
LINKS TO OTHER STUFF:
Favourites
Programming
Original Art
Games
Chinese Learning Projects:
- Book
- HSK 1
- HSK 5
- Homonyms Mnemonics