fnbige(input:u64)->u64{letmutcurrent=input;letmutmax=0;for_in0..16{letfive=current%100_000;iffive>max{max=five;}current/=10;// // optional optimization, might be harmful, but division is slow// // I wonder if dividing zero is fast though? Probably.// if current == 0 {// break;// }}max}
iterator
unwrapping is safe, because even with 0 we will have at least one element
(actually we will consider 0 15 times)
fnbige_string(input:&str)->u32{// use use atoi::FromRadix10; in real life to avoid checking for utf8 first.input.as_bytes().windows(5).filter_map(|x|std::str::from_utf8(x).ok()?.parse::<u32>().ok()).max().unwrap()}
Rust
🔗 the below code in a runnable playground
"imperative"
iterator
unwrapping is safe, because even with
0
we will have at least one element(actually we will consider
0
15 times)immutable
bad: leads to dividing bigger numbers
strings
good: can be longer than u64
usage