|
|
|
@ -1,14 +1,15 @@
|
|
|
|
|
use std::collections::HashMap; |
|
|
|
|
type CZS = HashMap<u64, u64>; |
|
|
|
|
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); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|