diff --git a/014/main.rs b/014/main.rs index c7883a9..c632854 100644 --- a/014/main.rs +++ b/014/main.rs @@ -1,14 +1,15 @@ use std::collections::HashMap; type CZS = HashMap; -struct Collatz { czs: CZS } +struct Collatz { czs: CZS, pub max_computed: u64 } impl Collatz { pub fn new() -> Collatz { - let mut res = Collatz { czs: HashMap::new() }; + let mut res = Collatz { czs: HashMap::new(), max_computed: 1 }; res.czs.insert(1, 1); res } pub fn compute(&mut self, n: u64) -> u64 { + if n > self.max_computed { self.max_computed = n; } match self.czs.get(&n) { Some(cl) => *cl, None => { @@ -37,8 +38,10 @@ fn main() { if clk > best_cl { best_cl = clk; best_n = k; + println!("new best {} -> {}", best_n, best_cl); } - //println!("{}: {}", k, clk); } println!("{} -> {}", best_n, best_cl); + println!("max_computed: {}", collatz.max_computed); + }