
If you think about it, this is also the same as finding the base 1,000 digits of a number. Getting both the quotient and remainder together is such a common operation that there is a built-in function for it: Table was used to tabulate the result (in this case, either True or False) for each value of n drawn from the list nums. Using these two functions with DigitSum, you have the first solution: To separate the first and last three digits of a six-digit number, you could use the Quotient and the remainder ( Mod) when dividing by 1,000: Using the built-in function IntegerDigits, you can define a handy function to compute the sum of the digits of an integer: Let’s start with a list of random six-digit numbers: In this post you’ll see four methods demonstrating various combinations of built-in Mathematica functions for working with lists and digits of integers. There are several different ways of solving this straightforward programming problem in Mathematica, and it’s instructive to compare them.


This week’s question comes from Craig, a hobbyist:įor each six-digit number in a list, how can I check whether the sums of the first and last three digits are equal?įor example, the sums of the first and last three digits of the number 123,222 are equal because 1 + 2 + 3 = 2 + 2 + 2.

You can submit your question directly to the Q&A Team using this form. Got questions about Mathematica? The Wolfram Blog has answers! We’ll regularly answer selected questions from users around the web.
