2016 Update

This commit is contained in:
Tina Müller 2016-12-05 22:15:40 +01:00
parent 948b86eafa
commit dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions

View file

@ -1,30 +1,12 @@
#![feature(zero_one)]
use std::num::One;
use std::ops::Add;
struct Fib<T> {
curr: T,
next: T,
}
impl<T> Fib<T> where T: One {
fn new() -> Self {
Fib {curr: T::one(), next: T::one()}
}
}
impl<T> Iterator for Fib<T> where T: Add<T, Output=T> + Copy {
type Item = T;
fn next(&mut self) -> Option<Self::Item>{
let new = self.curr + self.next;
self.curr = self.next;
self.next = new;
Some(self.curr)
}
}
use std::mem;
fn main() {
for i in Fib::<u64>::new() {
println!("{}", i);
let mut prev = 0;
// Rust needs this type hint for the checked_add method
let mut curr = 1usize;
while let Some(n) = curr.checked_add(prev) {
prev = curr;
curr = n;
println!("{}", n);
}
}