Ad
Numbers
Data Types
Integers
Algorithms
Logic
Code
Diff
  • // Removed loop
    fn digits (n: u64) -> usize
    {
      n.to_string().len()
    }
    
    • // Removed loop
    • fn digits (n: u64) -> usize
    • {
    • match n {
    • 0 ..= 9 => 1,
    • 10 ..= 99 => 2,
    • 100 ..= 999 => 3,
    • 1000 ..= 9999 => 4,
    • 10000 ..= 99999 => 5,
    • 100000 ..= 999999 => 6,
    • 1000000 ..= 9999999 => 7,
    • 10000000 ..= 99999999 => 8,
    • 100000000 ..= 999999999 => 9,
    • 1000000000 ..= 9999999999 => 10,
    • 10000000000 ..= 99999999999 => 11,
    • 100000000000 ..= 999999999999 => 12,
    • 1000000000000 ..= 9999999999999 => 13,
    • 10000000000000 ..= 99999999999999 => 14,
    • 100000000000000 ..= 999999999999999 => 15,
    • 1000000000000000 ..= 9999999999999999 => 16,
    • 10000000000000000 ..= 99999999999999999 => 17,
    • 100000000000000000 ..= 999999999999999999 => 18,
    • 1000000000000000000 ..= 9999999999999999999 => 19,
    • _ => 20,
    • }
    • n.to_string().len()
    • }