zlacker

[parent] [thread] 0 comments
1. arctic+(OP)[view] [source] 2019-11-11 01:50:22
No loops, and at least for a 64-bit type, you won't run out of stack space.

  fn digit_length_recursive(input: usize) -> usize {
      if input == 0 {
          0
      } else {
          1 + digit_length_recursive(input / 10)
      }
  }

  fn digit_length(input: usize) -> usize {
      std::cmp::max(digit_length_recursive(input), 1)
  }
[go to top]