Sum of the Year's Digits

Introduction

In an idle moment, having easily appreciated that the sum of the digits of this year, 2022, is equal to 6, I then wondered how many years since 1 AD have digits that add up to 6. For example 6 AD, 15 AD and so on.

Formula

I got my spreadsheet out and found the answer to be 52. Initially, with my series of years comprising two or more digits, starting at 10 in cell A15, I created this formula:

=IF(LEN(A15)=2,SUM(LEFT(A15,1)+RIGHT(A15,1)),

IF(LEN(A15)=3,SUM(LEFT(A15,1)+MID(A15,2,1)+RIGHT(A15,1)),

IF(LEN(A15)=4,SUM(LEFT(A15,1)+MID(A15,2,1)+MID(A15,3,1)+RIGHT(A15,1)),"")))

For one digit, I typed the answers by hand.

That formula works and I created some further analysis and a graph to confirm my answer.

Then I did a search to find a much more rational formula, by that I mean efficient and I found this one in various places on the web

=SUMPRODUCT(1*MID(A6,ROW(INDIRECT("1:"&LEN(A6))),1))

This works for one digit, two digits, all digits and it is much easier to read and appreciate.

Here is my graph:


The blue columns, left hand scale, show the frequencies of the sums of the digits and the orange line, right hand scale, shows differences between one result and another. For example, the first frequency is 3 and the second frequency is 7 so the difference between them is 4

There you are, just a bit of arithmetical fun ... of sorts.


Happy new year 2022


Duncan Williamson

01012022


No comments: