Skip to content

Instantly share code, notes, and snippets.

@5nyper
Created January 12, 2015 16:30
Show Gist options
  • Save 5nyper/499f5012e2cb18aa336c to your computer and use it in GitHub Desktop.
Save 5nyper/499f5012e2cb18aa336c to your computer and use it in GitHub Desktop.
Modded Example.rs
extern crate num;
use num::{BigUint, Zero, One};
use std::mem::replace;
fn fib(n: usize) -> usize {
let mut f0: BigUint = Zero::zero();
let mut f1: BigUint = One::one();
for _ in (0..n) {
let f2 = f0 + &f1;
// This is a low cost way of swapping f0 with f1 and f1 with f2.
f0 = replace(&mut f1, f2);
}
f0.to_string().len()
}
fn main() {
println!("fib(10000) = {}", fib(4784));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment