## Solution to Puzzle #86: Add The Digits and Count

This was a difficult puzzle, and I got only one response and a correct one from Ganesh Ramani, my friend from IITD Comp Science and now in Tokyo – well done!

To arrive at the solution, lets begin with Variation 1:

An easy way to think about the solution for this is to assume that you have 9 (sum) + 3 (number of digits) = 12 balls that you have to divide into 3 non-zero partitions, which if you try to calculate will be  (12-1) C (3-1) = 11 C 2 = 55. From each of these partitions, subtract 1 to arrive at the number. For example, one way to divide 12 into 3 partitions is 10, 1, 1 ==> the number is 900. Another way would be 5,3,4 ==> the number will be 423. Each of these numbers will have digits that add up to 9. 11 C 2 = 55, which is the answer for this variation.

Lets use this principle to arrive at the answer for Variation 2:

We can use the above principle to arrive at all the possible ways of 3 digits totaling up to 18 by doing (18+3-1) C (3-1) = 20 C 2 = 190.

However, the problem is that some of the digits could be 10 or above as well, which is not valid. We, therefore, need to subtract from 190 all the numbers where any of the digits is turning out to be 10 or more. Let’s assume that the first digit is 10 or more, that will imply that the sum of the last two digits is 8 or less, which is the same as all three digits number with a total of 8, which is equal to (8+3-1) C (3-1) = 10 C 2 = 45. Since any of the three digits can be 10 or above, we need to multiply 45 by 3 to arrive at all the possibilities where one of the digits is more than 10, i.e. 3 x 45 = 135.

therefore the number of solutions where the digits add up to 18 = 190 – 135 = 55.

Notice that there is a trivial way to arrive at this answer by doing the following:

– There is only one number where the first digit is 0, and the remaining two add up to 18, which is 099

– There are two numbers where the first digit is 1, and the remaining add up to 17, which are 189 and 198

– Similarly if the first digit is 2, then there are 3 possibilities…all the way up to the first digit being 9, when there are 10 solutions.

therefore the total is 1+2+3+….+10 = 55

This method, however, is brute force and does not scale when the numbers get larger.

Original version can be figured out in the same way as Variation 2:

Since there are 6 digits here, the answer will be 23 C 5 – (6 x (13 C 5)) = 33649 – 6*1287 = 25927

Hope you enjoyed the puzzle!

This entry was posted in Solution and tagged , , , . Bookmark the permalink.

### 1 Response to Solution to Puzzle #86: Add The Digits and Count

1. Girish Tutakne says:

I must confess that I tried and couldn’t solve the problem and am now struggling to understand the solution posted above as well. 😀
{"ft_lang_label":"__label__en","ft_lang_prob":0.94167316,"math_prob":0.9941135,"size":2555,"snap":"2022-40-2023-06","text_gpt3_token_len":717,"char_repetition_ratio":0.13249706,"word_repetition_ratio":0.007575758,"special_character_ratio":0.31311154,"punctuation_ratio":0.09153713,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9997633,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-10-05T21:10:32Z\",\"WARC-Record-ID\":\"<urn:uuid:580a6d05-46a8-42f1-b33c-341866cb8733>\",\"Content-Length\":\"90611\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:0e79cf52-fbd1-4aef-bf21-e27e2672b51a>\",\"WARC-Concurrent-To\":\"<urn:uuid:427cc29b-f568-44b8-967f-0c137302f2e2>\",\"WARC-IP-Address\":\"192.0.78.25\",\"WARC-Target-URI\":\"https://alokgoyal1971.com/2014/12/31/solution-to-puzzle-86-add-the-digits-and-count/\",\"WARC-Payload-Digest\":\"sha1:ZDBJXFUEV5CFS6CXN7QAFLONSVRA63C2\",\"WARC-Block-Digest\":\"sha1:DBTXOKF7FRHEN22DKQC2B2OVT3LUOHVM\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-40/CC-MAIN-2022-40_segments_1664030337668.62_warc_CC-MAIN-20221005203530-20221005233530-00571.warc.gz\"}"}