Browse Source

fun stat for 014

master
Coin de Gamma 2 years ago
parent
commit
2b24822354
  1. 9
      014/main.rs

9
014/main.rs

@ -1,14 +1,15 @@
use std::collections::HashMap; use std::collections::HashMap;
type CZS = HashMap<u64, u64>; type CZS = HashMap<u64, u64>;
struct Collatz { czs: CZS } struct Collatz { czs: CZS, pub max_computed: u64 }
impl Collatz { impl Collatz {
pub fn new() -> 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.czs.insert(1, 1);
res res
} }
pub fn compute(&mut self, n: u64) -> u64 { pub fn compute(&mut self, n: u64) -> u64 {
if n > self.max_computed { self.max_computed = n; }
match self.czs.get(&n) { match self.czs.get(&n) {
Some(cl) => *cl, Some(cl) => *cl,
None => { None => {
@ -37,8 +38,10 @@ fn main() {
if clk > best_cl { if clk > best_cl {
best_cl = clk; best_cl = clk;
best_n = k; best_n = k;
println!("new best {} -> {}", best_n, best_cl);
} }
//println!("{}: {}", k, clk);
} }
println!("{} -> {}", best_n, best_cl); println!("{} -> {}", best_n, best_cl);
println!("max_computed: {}", collatz.max_computed);
} }

Loading…
Cancel
Save