DataWeave programming challenge #8: Sum all digits to get a 1-digit number

About this video
Repeatedly sum the digits of a set of numbers in DataWeave until a single-digit result remains (the digital root). Clues and full solutions are in the companion article.
Resources
Transcript
Intro
Hi everyone, Alex here. In this DataWeave challenge we are going to take all of the digits from any numbers, and we are going to keep summing up these digits until we get to just a one-digit number. Let me demonstrate.
The challenge
Here is a problem that we have: we have several numbers here, we are going to sum them all, and then keep summing each digit until we end up with just one digit. In this case it’s going to be 2.
Let me give you another example. In this case we have 1 and 2, so if we sum 1 and 2 we end up with 3. Or in this case we have first 1, 2, 3 and then 4, 5, 6, and we end up with 3 — we can either do 123 plus 456 like this, 123 + 456, we end up with 579, so now we do 5 + 7 + 9, we end up with 21, and now 2 + 1, we end up with 3. Or another way to see it is 1 + 2 + 3 + 4 + 5 + 6, we end up with 21, so 2 + 1, we end up with 3.
Wrap-up
That’s all. I hope you like this challenge, it was very fun to do, and I will see you then in a different video. Bye!
More from DataWeave Challenges
- DataWeave programming challenge #1: Add numbers separated by paragraphs and get the max number
- DataWeave programming challenge #2: Rock Paper Scissors game score system
- DataWeave programming challenge #3: Count palindrome phrases using the Strings module
- DataWeave programming challenge #4: Solve the Tower of Hanoi mathematical puzzle