Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

added 35 characters in body
Source Link
badatgolf
  • 1.5k
  • 6
  • 25

C (gcc), (削除) 29 (削除ここまで) 27(削除) 27 (削除ここまで) 25 bytes

f(i){i=i%10+(ii=i?fi%10+f(i/10):0);0;}

Try it online! Try it online!

-2 bytes thanks to Giuseppe

-2 bytes thanks to c--

Takes input as int.

C's int isn't large enough for the last test case.

The bracket around the ternary is truly awful. Wish I could remove that(削除) The bracket around the ternary is truly awful. Wish I could remove that. (削除ここまで) Thanks c-- again.

C (gcc), (削除) 38 (削除ここまで) 36 bytes (no recursion).

a;f(i){for(a=0;i;i/=10)a+=i%10;a=a;}

Try it online!

-2 bytes thanks to Giuseppe

Takes input as int.

C's int isn't large enough for the last test case.

C (gcc), 56 bytes (no recursion) (outgolfed by c-- using recursion).

a,n;f(char*s){for(a=0,n=strlen(s);n--;++s)a+=*s-48;a=a;}

Takes input as string

Try it online!

C (gcc), (削除) 29 (削除ここまで) 27 bytes

f(i){i=i%10+(i?f(i/10):0);}

Try it online!

-2 bytes thanks to Giuseppe

Takes input as int.

C's int isn't large enough for the last test case.

The bracket around the ternary is truly awful. Wish I could remove that.

C (gcc), (削除) 38 (削除ここまで) 36 bytes (no recursion).

a;f(i){for(a=0;i;i/=10)a+=i%10;a=a;}

Try it online!

-2 bytes thanks to Giuseppe

Takes input as int.

C's int isn't large enough for the last test case.

C (gcc), 56 bytes (no recursion) (outgolfed by c-- using recursion).

a,n;f(char*s){for(a=0,n=strlen(s);n--;++s)a+=*s-48;a=a;}

Takes input as string

Try it online!

C (gcc), (削除) 29 (削除ここまで) (削除) 27 (削除ここまで) 25 bytes

f(i){i=i?i%10+f(i/10):0;}

Try it online!

-2 bytes thanks to Giuseppe

-2 bytes thanks to c--

Takes input as int.

C's int isn't large enough for the last test case.

(削除) The bracket around the ternary is truly awful. Wish I could remove that. (削除ここまで) Thanks c-- again.

C (gcc), (削除) 38 (削除ここまで) 36 bytes (no recursion).

a;f(i){for(a=0;i;i/=10)a+=i%10;a=a;}

Try it online!

-2 bytes thanks to Giuseppe

Takes input as int.

C's int isn't large enough for the last test case.

C (gcc), 56 bytes (no recursion) (outgolfed by c-- using recursion).

a,n;f(char*s){for(a=0,n=strlen(s);n--;++s)a+=*s-48;a=a;}

Takes input as string

Try it online!

added 62 characters in body
Source Link
badatgolf
  • 1.5k
  • 6
  • 25

C (gcc), 29 bytes (using recursion)(削除) 29 (削除ここまで) 27 bytes

f(i){i=i%10+(i/1?f(i/10):0);}

Try it online! Try it online!

-2 bytes thanks to Giuseppe

Takes input as int.

C's int isn't large enough for the last test case.

The bracket around the ternary is truly awful. Wish I could remove that.

C (gcc), 38(削除) 38 (削除ここまで) 36 bytes (no recursion).

a;f(i){for(a=0;i/1;ia=0;i;i/=10)a+=i%10;a=a;}

Try it online! Try it online!

-2 bytes thanks to Giuseppe

Takes input as int.

C's int isn't large enough for the last test case.

C (gcc), 56 bytes (no recursion) (outgolfed by c-- using recursion).

a,n;f(char*s){for(a=0,n=strlen(s);n--;++s)a+=*s-48;a=a;}

Takes input as string

Try it online!

C (gcc), 29 bytes (using recursion)

f(i){i=i%10+(i/1?f(i/10):0);}

Try it online!

Takes input as int.

C's int isn't large enough for the last test case.

The bracket around the ternary is truly awful. Wish I could remove that.

C (gcc), 38 bytes (no recursion).

a;f(i){for(a=0;i/1;i/=10)a+=i%10;a=a;}

Try it online!

Takes input as int.

C's int isn't large enough for the last test case.

C (gcc), 56 bytes (no recursion) (outgolfed by c-- using recursion).

a,n;f(char*s){for(a=0,n=strlen(s);n--;++s)a+=*s-48;a=a;}

Takes input as string

Try it online!

C (gcc), (削除) 29 (削除ここまで) 27 bytes

f(i){i=i%10+(i?f(i/10):0);}

Try it online!

-2 bytes thanks to Giuseppe

Takes input as int.

C's int isn't large enough for the last test case.

The bracket around the ternary is truly awful. Wish I could remove that.

C (gcc), (削除) 38 (削除ここまで) 36 bytes (no recursion).

a;f(i){for(a=0;i;i/=10)a+=i%10;a=a;}

Try it online!

-2 bytes thanks to Giuseppe

Takes input as int.

C's int isn't large enough for the last test case.

C (gcc), 56 bytes (no recursion) (outgolfed by c-- using recursion).

a,n;f(char*s){for(a=0,n=strlen(s);n--;++s)a+=*s-48;a=a;}

Takes input as string

Try it online!

added 441 characters in body
Source Link
badatgolf
  • 1.5k
  • 6
  • 25

C (gcc), 29 bytes (using recursion)

f(i){i=i%10+(i/1?f(i/10):0);}

Try it online!

Takes input as int.

C's int isn't large enough for the last test case.

The bracket around the ternary is truly awful. Wish I could remove that.

C (gcc) , 38 bytes (takes input by intno recursion).

a;f(i){for(a=0;i/1;i/=10)a+=i%10;a=a;}

Try it online!

Takes input as int.

C's int isn't large enough for the last test case.

C (gcc), 56 bytes (takes input as stringno recursion) (outgolfed by c-- using recursion).

a,n;f(char*s){for(a=0,n=strlen(s);n--;++s)a+=*s-48;a=a;}

Takes input as string

Try it online!

C (gcc), 38 bytes (takes input by int).

a;f(i){for(a=0;i/1;i/=10)a+=i%10;a=a;}

Try it online!

C's int isn't large enough for the last test case.

C (gcc), 56 bytes (takes input as string) (outgolfed by c--.

a,n;f(char*s){for(a=0,n=strlen(s);n--;++s)a+=*s-48;a=a;}

Try it online!

C (gcc), 29 bytes (using recursion)

f(i){i=i%10+(i/1?f(i/10):0);}

Try it online!

Takes input as int.

C's int isn't large enough for the last test case.

The bracket around the ternary is truly awful. Wish I could remove that.

C (gcc) , 38 bytes (no recursion).

a;f(i){for(a=0;i/1;i/=10)a+=i%10;a=a;}

Try it online!

Takes input as int.

C's int isn't large enough for the last test case.

C (gcc), 56 bytes (no recursion) (outgolfed by c-- using recursion).

a,n;f(char*s){for(a=0,n=strlen(s);n--;++s)a+=*s-48;a=a;}

Takes input as string

Try it online!

added 542 characters in body
Source Link
badatgolf
  • 1.5k
  • 6
  • 25
Loading
deleted 3 characters in body
Source Link
badatgolf
  • 1.5k
  • 6
  • 25
Loading
Source Link
badatgolf
  • 1.5k
  • 6
  • 25
Loading

AltStyle によって変換されたページ (->オリジナル) /