Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Find the sum of digits in the positional representation of an integer
ResourceFunction["DigitSum"][n] gives the sum of digits in the base-10 representation of the integer n. | |
ResourceFunction["DigitSum"][n,b] gives the sum of digits in the base-b representation of integer n. |
Compute a digit sum in base 10:
| In[1]:= |
| Out[1]= |
Compute another digit sum:
| In[2]:= |
| Out[2]= |
Compute a digit sum in another numerical base:
| In[3]:= |
| Out[3]= |
Compare this to the output of IntegerDigits:
| In[4]:= |
| Out[4]= |
| In[5]:= |
| Out[5]= |
DigitSum ignores the sign of its input:
| In[6]:= |
| Out[6]= |
The digit sum of 0 is 0 in any base:
| In[7]:= |
| Out[7]= |
| In[8]:= |
| Out[8]= |
This work is licensed under a Creative Commons Attribution 4.0 International License