Name this (silly) function

I’m certain that I once heard a name for this
(other than “silly”) but can’t remember it now:

Take a number, say 849672948.

Add up the digits:

8 + 4 + 9 + 6 + 7 + 2 + 9 + 4 + 8 = 57

Repeat until you arrive at a single digit:

5 + 7 = 12

1 + 2 = 3

That’s it.

Were one to write a program to do this (and I can’t for
the life of me imagine why anyone would), it would easily
lend itself to recursion.

So, what’s it called (again, other than “silly”)?

Peter.

BoatyMcBoatFace(iValue as Integer) as Integer

or

SumDigits(iValue as Integer) as Integer

Where the first few instructions of SumDigits splits iValue into individual digits. A parent function makes shrinking to the smallest size optional, just call the desired function.

ReduceToSmallestSum(iValue as Integer) as Integer

Which would have the while loop that goes until the sum is one digit.

It’s not really recursion, but it’s how I’d build it – with options for myself.

2 Likes

SumOverDigits

SumOfDigits

SumDigits

TenPoundsOfDigitsInAFivePoundInteger

According to stackoverflow, just use mod 9.

3 Likes

Maybe Digital Root

2 Likes

While I thought about it at first (that’s a known property of mod 9), there’s an edge case: when the sum equals 9, 9 mod 9 equals 0. So, for example, 45 returns 0.
But, well, since one knows only 0 can result to 0, any result being 0 with a non-null starting number means it’s actually 9.

What‘s wrong with ’silly’? Maybe a bit more declararive; silly_sum_digits?

Yes, the stackoverflow post mentions that edge case and how to handle it.

I was hoping it had some “official” name, perhaps in
memory of its inventor - “van Rentaal’s function”
for example.

But then who would want to be immortalised for something
so trivial?

Peter.

“Rodwells” function :sunglasses: .

2 Likes

Yes, it has an official name:

2 Likes

No, no, no! I only want to be immortalised for my work in quantum chromodynamics (if I ever do any).

Digit sum?

Digit sum?

No.

For example, the digit sum of the decimal number 9045 9+0+4+5=18

Digital Root = 9

You‘re right. I overlooked your post.

that’s an easy one, call it silly

So the function should be called

mod9theHardWay()

No because it isn’t exactly mod9 as stated previously :wink:

“AlmostMod9TheHardWay()” then :wink:.

3 Likes