{"id":3964,"date":"2024-02-03T14:27:27","date_gmt":"2024-02-03T20:27:27","guid":{"rendered":"https:\/\/laurentlessard.com\/bookproofs\/?p=3964"},"modified":"2024-02-03T16:22:56","modified_gmt":"2024-02-03T22:22:56","slug":"how-many-times-can-you-add-up-the-digits","status":"publish","type":"post","link":"https:\/\/laurentlessard.com\/bookproofs\/how-many-times-can-you-add-up-the-digits\/","title":{"rendered":"How many times can you add up the digits?"},"content":{"rendered":"<p>This week&#8217;s <a href=\"https:\/\/thefiddler.substack.com\/p\/how-many-times-can-you-add-up-the\">Fiddler<\/a> is a puzzle about adding digits over and over again.<\/p>\n<blockquote><p>\nFor any positive, base-10 integer $n$, define $f(n)$ as the number of times you have to add up its digits until you get a one-digit number. For example, $f(23) = 1$ because $2+3 = 5$, a one-digit number. Meanwhile, $f(888) = 2$, since $8+8+8 = 24$, a two-digit number, and then adding up those digits gives you $2+4 = 6$, a one-digit number. Find the smallest whole number $n$ such that $f(n) = 4$.<\/p>\n<p><em>Extra Credit:<\/em> For how many whole numbers $n$ between $1$ and $10,000$ does $f(n) = 3$?\n<\/p><\/blockquote>\n<p>My solution:<br \/>\n<a href=\"javascript:Solution('soln_adddigits','toggle_adddigits')\" id=\"toggle_adddigits\">[Show Solution]<\/a><\/p>\n<div id=\"soln_adddigits\" style=\"display: none\">\n<p>Let $a_n$ be the smallest integer $n$ such that $f(a_n) = n$. We can calculate the first few values manually.<\/p>\n<ul>\n<li> $a_1 = 10$. This must be the case since every one-digit number has $f(n)=0$, and $10$ is the smallest two-digit number and $f(10)=1$.\n<li> $a_2 = 19$. We seek the smallest number such that the sum of its digits needs to be summed once more to get to a one-digit number. In other words, we want the smallest number whose digits sum to $10$. This requires at least two digits and can be done in two ways ($19$ and $91$). Using more than two digits leads to larger numbers so we can exclude these possibilities.\n<li> $a_3 = 199$. Now, we seek the smallest number whose digits sum to $19$. This is impossible with two digits (smallest sum is $9+9=18$), so we try with three. This can be done with a $1$ as the first digit ($1+9+9$), so this must be the answer.\n<\/ul>\n<p>The pattern is now clear. For all $n\\geq 1$, $a_{n+1}$ is the smallest integer whose digits sum to $a_n$. Based on the pattern, let&#8217;s suppose that<br \/>\n\\[<br \/>\na_n = 1\\,\\underbrace{9\\,9\\,\\cdots\\,9}_{k_n\\text{ times}}<br \/>\n\\qquad\\text{for }n=2,3,\\dots<br \/>\n\\]where $k_2=1$ and $k_3=2$. Now $a_{n+1}$ is the smallest number whose digits sum to $a_n$. How many digits must $a_n$ have? Rewrite $a_n$ in a particular way:<br \/>\n\\begin{align}<br \/>\na_n &#038;= 1\\,\\underbrace{9\\,9\\,\\cdots\\,9}_{k_n\\text{ times}}\\\\<br \/>\n&#038;= 2\\cdot 10^{k_n}-1 \\\\<br \/>\n&#038;= 2\\left( 10^{k_n}-1\\right)+1 \\\\<br \/>\n&#038;= 2\\cdot 9\\cdot \\left(  \\frac{10^{k_n}-1}{10-1}\\right)+1\\\\<br \/>\n&#038;= 2\\cdot 9\\cdot \\left( 1+10+10^2+\\cdots+10^{k_n-1}\\right) +1 \\\\<br \/>\n&#038;= 9 \\cdot \\bigl(\\, \\underbrace{2\\,2\\,\\cdots\\,2}_{k_n\\text{ times}}\\,\\bigr) + 1<br \/>\n\\end{align}where we used the formula for a <a href=\"https:\/\/en.wikipedia.org\/wiki\/Geometric_series#Sum\">finite geometric series<\/a> in the third step. Based on this representation, it is clear that $a_{n+1}$ requires more than $\\underbrace{2\\,2\\,\\cdots\\,2}_{k_n\\text{ times}}$ digits, since even if we made all the digits $9$ it would not be enough. W should add the extra $+1$ digit at the front of the number to get the smallest number possible. This leads to:<br \/>\n\\[<br \/>\na_{n+1} = 1\\underbrace{9\\,9\\,\\cdots\\,9}_{\\underbrace{2\\,2\\,\\cdots\\,2}_{k_n\\text{ times}}\\text{ times}}<br \/>\n\\]So $a_{n+1}$ is of the same form as $a_n$, and we find:<br \/>\n\\[<br \/>\nk_{n+1} = \\underbrace{2\\,2\\,\\cdots\\,2}_{k_n\\text{ times}}\\qquad\\text{for }k=2,3,\\dots.<br \/>\n\\]So although the sequence $f(n)$ seemed to grow at a moderate pace, for $n=0,1,2,3$, we find that<br \/>\n\\[<br \/>\nf(4) = 19,\\!999,\\!999,\\!999,\\!999,\\!999,\\!999,\\!999<br \/>\n\\]That escalated quickly!<\/p>\n<p>In general, we can write the full recursion as:<br \/>\n\\begin{align}<br \/>\na_1 &#038;= 10,\\\\<br \/>\na_2 &#038;= 19,\\\\<br \/>\na_{n+1} &#038;= 2\\cdot 10^{(a_n-1)\/9}-1\\qquad\\text{for }n=2,3,\\dots<br \/>\n\\end{align}<\/p>\n<h3>Extra credit<\/h3>\n<p>The most straightforward way to count how many $n$ between $1$ and $10,\\!000$ satisfy $f(n)=3$ is to write a short script. Here is a two-line script in Julia that does the job:<\/p>\n<pre>\r\nf(n) = n < 10 ? 0 : 1 + f(sum(digits(n)))\r\nlength( [n for n in 1:10000 if f(n) == 3] )\r\n<\/pre>\n<p>and the answer is 945.\n<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>This week&#8217;s Fiddler is a puzzle about adding digits over and over again. For any positive, base-10 integer $n$, define $f(n)$ as the number of times you have to add up its digits until you get a one-digit number. For example, $f(23) = 1$ because $2+3 = 5$, a one-digit number. Meanwhile, $f(888) = 2$, &hellip; <a href=\"https:\/\/laurentlessard.com\/bookproofs\/how-many-times-can-you-add-up-the-digits\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How many times can you add up the digits?&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[42],"tags":[37,43,17,15],"class_list":["post-3964","post","type-post","status-publish","format-standard","hentry","category-the-fiddler","tag-coding","tag-fiddler","tag-induction","tag-recursion"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/posts\/3964","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/comments?post=3964"}],"version-history":[{"count":7,"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/posts\/3964\/revisions"}],"predecessor-version":[{"id":3975,"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/posts\/3964\/revisions\/3975"}],"wp:attachment":[{"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/media?parent=3964"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/categories?post=3964"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/tags?post=3964"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}