Algorithms
fn digits(mut n: u64) -> usize { std::iter::from_fn(|| { n = n / 10; Some(n) }). take_while(|n| *n > 0) .count() + 1 }
use std::collections::BTreeMap;fn digits(n: u64) -> usize {let powers = (0..20).map(|n| (if n == 0 { 0 } else { 10_u64.pow(n) },n as usize + 1)).collect::<BTreeMap<_, _>>();return *powers.range(..=n).last().unwrap().1;- fn digits(mut n: u64) -> usize {
- std::iter::from_fn(|| { n = n / 10; Some(n) }).
- take_while(|n| *n > 0)
- .count() + 1
- }