Skip to main content
Commonmark migration
Source Link

C (gcc), 50 48 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.

Thanks to ceilingcat for the suggestion.

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

Try it online!


##Original version: 71 57 bytes

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!

C (gcc), 50 48 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.

Thanks to ceilingcat for the suggestion.

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!

C (gcc), 50 48 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.

Thanks to ceilingcat for the suggestion.

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!

Code shortening
Source Link
ErikF
  • 4.7k
  • 8
  • 11

C (gcc), 5050 48 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.

Thanks to ceilingcat for the suggestion.

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

Try it online!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!

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!

C (gcc), 50 48 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.

Thanks to ceilingcat for the suggestion.

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!

Code shortening
Source Link
ErikF
  • 4.7k
  • 8
  • 11

C (gcc), 71 5750 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!

C (gcc), 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!

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!

Code shortening
Source Link
ErikF
  • 4.7k
  • 8
  • 11
Loading
Code shortening
Source Link
ErikF
  • 4.7k
  • 8
  • 11
Loading
Source Link
ErikF
  • 4.7k
  • 8
  • 11
Loading