Skip to content

Instantly share code, notes, and snippets.

@Taneb
Created February 8, 2014 01:24
Show Gist options
  • Save Taneb/8875238 to your computer and use it in GitHub Desktop.
Save Taneb/8875238 to your computer and use it in GitHub Desktop.
use std::iter::Unfold;
use std::os::args;
fn next(arg : &mut (int, int)) -> Option<int> {
let (lo, hi) = *arg;
*arg = (hi, lo + hi);
Some(lo)
}
fn main() {
let argsV = args();
let argI = argsV.iter().idx(1).map_or(20, |arg0| {from_str(arg0.clone()).unwrap_or(2)});
for fib in Unfold::new((0,1), next).take(argI) {
println!("{}", fib);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment