Fibonacci Stuff
This file contains 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 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 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