September Morn Update
This commit is contained in:
parent
4e2d22a71d
commit
aac6731f2c
6856 changed files with 141342 additions and 21127 deletions
|
|
@ -1,14 +1,7 @@
|
|||
#![feature(conservative_impl_trait)]
|
||||
|
||||
fn main() {
|
||||
for num in fibonacci_gen(10) {
|
||||
println!("{}", num);
|
||||
fn fib(n: u32) -> u32 {
|
||||
match n {
|
||||
0 => 0,
|
||||
1 => 1,
|
||||
n => fib(n - 1) + fib(n - 2),
|
||||
}
|
||||
}
|
||||
|
||||
fn fibonacci_gen(terms: i32) -> impl Iterator<Item=u64> {
|
||||
let sqrt_5 = 5.0f64.sqrt();
|
||||
let p = (1.0 + sqrt_5) / 2.0;
|
||||
let q = 1.0/p;
|
||||
(1..terms).map(move |n| ((p.powi(n) + q.powi(n)) / sqrt_5 + 0.5) as u64)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue