Last active
August 29, 2015 14:10
-
-
Save yelinaung/a58a634bf1a5a65a72bf to your computer and use it in GitHub Desktop.
Fibonacci Stuff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import () | |
| func main() { | |
| for i := 0; i < 50; i++ { | |
| // fmt.Printf("i is %d and result is %d.\n", i, fibo(i)) | |
| fibo(i) | |
| } | |
| } | |
| func fibo(n int) int { | |
| if n <= 1 { | |
| return n | |
| } else { | |
| return fibo(n-1) + fibo(n-2) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def fibo(n) | |
| return n if ( 0..1 ).include? n | |
| fibo( n - 1 ) + fibo( n - 2 ) | |
| end | |
| (0...30).each do |i| | |
| puts fibo(i) | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fn main() { | |
| for num in range(1i, 50) { | |
| fibo(num); | |
| } | |
| } | |
| fn fibo(n: int) -> int { | |
| if n <= 1 { | |
| return n; | |
| } else { | |
| return fibo(n - 1) + fibo(n - 2); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment