All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Numbers
Less than 100 (Posted on 2021-02-14) Difficulty: 2 of 5
Pick up at random a 3-digit number and decrease it by the sum of its digits.
Clearly,applying this procedure again and again you will hit zero no matter how big your initial number was .
How many iterations at most are needed and how many numbers cause it?

No Solution Yet Submitted by Ady TZIDON    
Rating: 4.0000 (1 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution computer solution | Comment 2 of 3 |
I would call it 80 steps for the largest ten 3-digit numbers.

clc
max=0;
for n0=100:999
    n=n0;
    for gen=1:1000
       n=n-sod(n);
       if n0==999
          disp([gen n]) 
       end
       if n==0
           break
       end
    end
    disp([n0 gen])
    if gen>max
        max=gen;
    end
end
disp(max)


requiring file sod.m:

function sd = sod(n) 
    s=0;
    dgts=num2str(n) ;
    l=length(dgts) ;
    dgts=string(dgts);
    for i=1:l
        s=s+double(substr(dgts,i));
    end
    sd=s;
end

also substr.m:

function outstr = substr(x,r)
 c=char(x);
 c2=c(r);
 outstr=string(c2);
end


produces, firstly a list of how many steps are needed for each 3-digit number:

   100    11
   101    11
   102    11
   103    11
   104    11
   105    11
   106    11
   107    11
   108    11
   109    11
   110    12
   111    12
   112    12
   113    12
   114    12
   115    12
   116    12
   117    12
   118    12
   119    12
   120    13
   121    13
   122    13
   123    13
   124    13

...

   983    79
   984    79
   985    79
   986    79
   987    79
   988    79
   989    79
   990    80
   991    80
   992    80
   993    80
   994    80
   995    80
   996    80
   997    80
   998    80
   999    80

and the 80 steps starting with 999:

 after # remaining
  steps  
     1   972
     2   954
     3   936
     4   918
     5   900
     6   891
     7   873
     8   855
     9   837
    10   819
    11   801
    12   792
    13   774
    14   756
    15   738
    16   720
    17   711
    18   702
    19   693
    20   675
    21   657
    22   639
    23   621
    24   612
    25   603
    26   594
    27   576
    28   558
    29   540
    30   531
    31   522
    32   513
    33   504
    34   495
    35   477
    36   459
    37   441
    38   432
    39   423
    40   414
    41   405
    42   396
    43   378
    44   360
    45   351
    46   342
    47   333
    48   324
    49   315
    50   306
    51   297
    52   279
    53   261
    54   252
    55   243
    56   234
    57   225
    58   216
    59   207
    60   198
    61   180
    62   171
    63   162
    64   153
    65   144
    66   135
    67   126
    68   117
    69   108
    70    99
    71    81
    72    72
    73    63
    74    54
    75    45
    76    36
    77    27
    78    18
    79     9
    80     0   

Edited on February 14, 2021, 9:03 am

Edited on February 14, 2021, 9:08 am
  Posted by Charlie on 2021-02-14 08:59:24

Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (23)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information