Ad
  • Custom User Avatar

    I forgot about truncation (facepalm).

    Great solution!

  • Custom User Avatar

    I chose not to put the comparison there because, by doing that, it executes that instruction on every loop iteration, which immensely slows down the total run time. Although there are 2 more lines of code, the actualy number of times that comparison is made is much, much less.

  • Default User Avatar

    Can avoid an extra (length > max_length) comparison by having the first check in the correct part of the while loop. My newer solution demonstrates this.