Skip to main content
4 of 6
Code shortening
ErikF
  • 4.7k
  • 8
  • 11

C (gcc), 50 bytes

An explicit carry flag wasn't necessary after restructuring the loop to end as soon as no carry would happen. The 9->A adjustment is performed during the loop check.

f(char*s){for(s+=9;(*s+=(*s-57)?1:8)>90;*s--=48);}

Try it online!


##Original version: 71 57 bytes

This version uses a carry flag to propagate updates: I set it to truthy to begin the increment. The string is modified in-place and only accepts 0-9, A-Z. The tricky part was making sure that 9->A got handled correctly on carries.

Edit: I repurposed the input pointer as the carry flag.

f(s){for(char*t=s+9;s;)*t--+=(s=++*t>90)?-43:7*!(*t-58);}

Try it online!

ErikF
  • 4.7k
  • 8
  • 11