Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Solution 119456

Submitted on 27 Jul 2012 by Aurelien Queffurust

Correct

111Size
Leading solution size is 29.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test
Code Input and Output
1
Pass
 
%%
n=3;
x=7;
q=2;
y_correct = 1;
assert(isequal(whatdigit(n,x,q),y_correct))
Z =
1
init =
     3
counter =
     1
N =
     9
counter =
     2
Z =
9
N =
    27
counter =
     3
Z =
27
N =
     6    21
counter =
     4
Z =
81
N =
    24     3
counter =
     5
Z =
243
N =
     6    12     9
counter =
     6
Z =
729
N =
    21     6    27
counter =
     7
Z =
2187
N =
     6     3    24    21
y =
     1
2
Pass
 
%%
n=5;
x=5;
q=3;
y_correct = 2;
assert(isequal(whatdigit(n,x,q),y_correct))
Z =
1
init =
     5
counter =
     1
N =
    25
counter =
     2
Z =
25
N =
    10    25
counter =
     3
Z =
125
N =
     5    10    25
counter =
     4
Z =
625
N =
    30    10    25
counter =
     5
Z =
3125
N =
    15     5    10    25
y =
     2
3
Pass
 
%%
n=7;
x=7;
q=3;
y_correct = 3;
assert(isequal(whatdigit(n,x,q),y_correct))
Z =
1
init =
     7
counter =
     1
N =
    49
counter =
     2
Z =
49
N =
    28    63
counter =
     3
Z =
343
N =
    21    28    21
counter =
     4
Z =
2401
N =
    14    28     0     7
counter =
     5
Z =
16807
N =
     7    42    56     0    49
counter =
     6
Z =
117649
N =
     7     7    49    42    28    63
counter =
     7
Z =
823543
N =
    56    14    21    35    28    21
y =
     3
4
Pass
 
%%
n=21;
x=17;
q=18;
y_correct = 8;
assert(isequal(whatdigit(n,x,q),y_correct))
Z =
1
init =
    21
counter =
     1
N =
     4     4     1
counter =
     2
Z =
441
N =
     8    12     6     1
counter =
     3
Z =
9261
N =
    18    13    14     8     1
counter =
     4
Z =
194481
N =
     2    19    17    12    20    10     1
counter =
     5
Z =
4084101
N =
     8     4    16    16     6     1     2     1
counter =
     6
Z =
85766121
N =
    16    18    19    19    18     8     5     4     1
counter =
     7
Z =
1801088541
N =
  Columns 1 through 10
     2    17     8     2     1    16    24    18    13     6
  Column 11
     1
counter =
     8
Z =
37822859361
N =
  Columns 1 through 10
     6    17    23    12     6    18    18    23    15    15
  Columns 11 through 12
     8     1
counter =
     9
Z =
794280046581
N =
  Columns 1 through 10
    14    25    17     8    18     8     0     8    16    16
  Columns 11 through 13
    21    10     1
counter =
    10
Z =
16679880978201
N =
  Columns 1 through 10
     2    13    18    20    25    25    24     8    18    23
  Columns 11 through 15
    23    12     2     2     1
counter =
    11
Z =
350277500542221
N =
  Columns 1 through 10
     6    13     5     4    16    21    17     5     0    10
  Columns 11 through 16
    13     8     6     6     4     1
counter =
    12
Z =
7355827511386641
N =
  Columns 1 through 10
    14    13    13    15    21    12    16    17     7     3
  Columns 11 through 17
     7    19    20    18    14     6     1
counter =
    13
Z =
154472377739119461
N =
  Columns 1 through 10
     2    11    13    12    18    11     8    17    21    21
  Columns 11 through 19
    13    21    11     3    19    17    16     8     1
counter =
    14
Z =
3243919932521508681
N =
  Columns 1 through 10
     6     7    10    10    21    11    19    27    15     7
  Columns 11 through 20
    12     9     4    11     5    16    20    22    10     1
counter =
    15
Z =
68122318582951682301
N =
  Columns 1 through 10
    12    22    10     5     6     8     5    17    18    21
  Columns 11 through 20
    12    20    19     7    13    22    12     8     3     2
  Column 21
     1
counter =
    16
Z =
1430568690241985328321
N =
  Columns 1 through 10
     2     9    10     3    10    17    22    20    24     9
  Columns 11 through 20
     4    10     6    19    25    18    11     7    18    14
  Columns 21 through 23
     7     4     1
counter =
    17
Z =
30041942495081691894741
N =
  Columns 1 through 10
     6     3     0     8     6    19    17     8    10    22
  Columns 11 through 20
    19     5    16    10    13    24    11    17    26    17
  Columns 21 through 24
    18    15     6     1
y =
     8
5
Pass
 
%%
n=201;
x=123;
q=241;
y_correct = 7;
assert(isequal(whatdigit(n,x,q),y_correct))
Z =
1
init =
   201
counter =
     1
N =
     4     0     4     0     1
counter =
     2
Z =
40401
N =
     8     0    12     0     6     0     1
counter =
     3
Z =
8120601
N =
    16     2    12     1    14     0     8     0     1
counter =
     4
Z =
1632240801
N =
  Columns 1 through 10
     2    12     7    10     7    10     2    20     0    10
  Columns 11 through 12
     0     1
counter =
     5
Z =
328080401001
N =
  Columns 1 through 10
     6     4    19     2    24     0    16     0     6     0
  Columns 11 through 14
     1     2     0     1
counter =
     6
Z =
65944160601201
N =
  Columns 1 through 10
    12    10    24    13    17     6    16     1    18     0
  Columns 11 through 16
     8     4     1     4     0     1
counter =
     7
Z =
13254776280841401
N =
  Columns 1 through 10
     2     6     5    13    10    19    18    19    11    22
  Columns 11 through 19
     2    24     8    10    12     1     6     0     1
counter =
     8
Z =
2664210032449121601
N =
  Columns 1 through 10
     4    12    14    14    10     6     2     1     6     4
  Columns 11 through 20
    11    10    22     6    13     3    14     1     8     0
  Column 21
     1
counter =
     9
Z =
535506216522273441801
N =
  Columns 1 through 10
    10     6    15    13     5    17     4     8    14    11
  Columns 11 through 20
    10     9     6    16     8    15    11     6    20     1
  Columns 21 through 23
    10     0     1
counter =
    10
Z =
107636749520976961802001
N =
  Columns 1 through 10
     2     0    15    12    13    18    17    14    25    14
  Columns 11 through 20
    13     5    20    14    21    25    18    11    22     1
  Columns 21 through 26
    12     0     2     2     0     1
counter =
    11
Z =
21634986653716369322202201
N =
  Columns 1 through 10
     4     2    14     7    14    21    20    21    20    16
  Columns 11 through 20
    12    19     5    19     7    18    21    12    13     7
  Columns 21 through 28
     6     2     6     4     2     4     0     1
counter =
    12
Z =
4348632317396990233762642401
N =
  Columns 1 through 10
     8     6    12    19    16    14    10     9     4    17
  Columns 11 through 20
     7    25    15    27    24     9    13     6     8    17
  Columns 21 through 30
    15    11    18    10    10    12     2     6     0     1
counter =
    13
Z =
874075095796795036986291122601
N =
  Columns 1 through 10
    16    14    16     7    18    10     7    23    10    23
  Columns 11 through 20
    23    19    23    24    17     9    11    12    21    22
  Columns 21 through 30
    21    12    24     4    11     5     5    14     2     8
  Columns 31 through 32
     0     1
counter =
    14
Z =
175689094255155802434244515642801
N =
  Columns 1 through 10
     2    14    11    19    21    24     8    27     8    13
  Columns 11 through 20
    14    12     7    15    11    21     5    12     8     8
  Columns 21 through 30
    12     7    12    10    14     6    15    13    13    10
  Columns 31 through 35
    20     2    10     0     1
counter =
    15
Z =
35313507945286316289283147644203001
N =
  Columns 1 through 10
     6    10     9     7     9    11     3    19    18    15
  Columns 11 through 20
    19     8    21    14    14     8    15     5    22    20
  Columns 21 through 30
    12    25     8    10    11    15    16    15    14     8
  Columns 31 through 37
     4     8     0     3     2     0     1
counter =
    16
Z =
7098015097002549574145912676484803201
N =
  Columns 1 through 10
    14     0    25    16     9    10    10     1    23    14
  Columns 11 through 20
     9     7     4    10    10    23    14    23    13     9
  Columns 21 through 30
    12    11    22     7    13    13    16    18    15    22
  Columns 31 through 39
    12    24     4    14     4     3     4     0     1
counter =
    17
Z =
1426701034497512464403328447973445443401
N =
  Columns 1 through 10
     2     8     5    16    16     6     9     0     7     8
  Columns 11 through 20
    11    22    18    19     9     9     9    14    12    14
  Columns 21 through 30
     4    10     6     7    19    10    16    18    22    21
  Columns 31 through 40
    15    15    11    14    12    13    10    12     3     6
  Columns 41 through 42
     0     1
counter =
    18
Z =
286766907934000005345069018042662534123601
N =
  Columns 1 through 10
     4    16    14    22    18    19    24     6    23    18
  Columns 11 through 20
    13    17     3     4     0     0     0    10     6    13
  Columns 21 through 30
    13     4    17    18     6    11    16     1    16     4
  Columns 31 through 40
    16    14    10    16     8    13     5     8     7    14
  Columns 41 through 44
     3     8     0     1
counter =
    19
Z =
57640148494734001074358872626575169358843801
N =
  Columns 1 through 10
    10    14    17    15     6     6     8    17    12    26
  Columns 11 through 20
    12    23    10    15     3     4     2     0    15     8
  Columns 21 through 30
    13    14    19    21    22    12    19     6    18    12
  Columns 31 through 40
    20    15     9    17    19    12    19    19    21    16
  Columns 41 through 46
    14    20     3    10     0     1
counter =
    20
Z =
11585669847441534215946133397941609041127604001
N =
  Columns 1 through 10
     2     2    11    17    15    20    17    24    22    17
  Columns 11 through 20
    22    12    15     6    14     7    13     7     6    12
  Columns 21 through 30
    19    13    21     6    12     7     9    21    17    27
  Columns 31 through 40
    15    11    16     1    24     0    17     2     6     5
  Columns 41 through 49
    15    14     7    14     0     4     2     0     1
counter =
    21
Z =
2328719639335748377405172812986263417266648404201
N =
  Columns 1 through 10
     4     6     6    19    16    10    25    13    15    24
  Columns 11 through 20
     9    15    13    17    13    23    10    22    17    15
  Columns 21 through 30
     7    14     2    19     5    23     4    12    19    18
  Columns 31 through 40
    21    12    18     8    14     5    18     5    19    14
  Columns 41 through 50
    18    14    22    12     8    12     4     4     4     0
  Column 51
     1
counter =
    22
Z =
468072647506485423858439735410238946870596329244401
N =
  Columns 1 through 10
     8    12    20     6    22     4    19    10    20    14
  Columns 11 through 20
     7    17     8    22    14    16     9    10    18    13
  Columns 21 through 30
    24    13    14    22    17    15    17    11     7     4
  Columns 31 through 40
     5     6    18    21    16    21    20    20     8    17
  Columns 41 through 50
    18    17    15    10    21     6    17    10    12     4
  Columns 51 through 53
     6     0     1
counter =
    23
Z =
94082602148803570195546386817458028320989862178124601
N =
  Columns 1 through 10
    18     8     9    20     4    20     2    10     2    10
  Columns 11 through 20
    17    20     8    14    10    17     5     9    18    11
  Columns 21 through 30
    19    13    17    10    22    15    24     8    22     9
  Columns 31 through 40
    17    20     5    12    16     8    12     3    20    16
  Columns 41 through 50
    27    24    21    12     8    16    17     9    12     9
  Columns 51 through 55
    14     4     8     0     1
counter =
    24
Z =
18910603031909517609304823750309063692518962297803044801
N =
  Columns 1 through 10
     2    16    19    10     9    13     0    12     0     9
  Columns 11 through 20
     2    21     1    27    10    11    19    13     7    24
  Columns 21 through 30
     6     9    11    16     8    14    16    13     7    11
  Columns 31 through 40
     0    21     0    21     6    18    21    10    19     4
  Columns 41 through 50
    21    19    20    13    10    20    16    25     7    14
  Columns 51 through 58
     0    11     8    20     4    10     0     1
counter =
    25
Z =
3801031209413813039470269573812121802196311421858412005001
N =
  Columns 1 through 10
     6    16     3    10     0     7     2     7     1    20
  Columns 11 through 20
     8    11    10    17     5    14     1     9    18    11
  Columns 21 through 30
    23     4    11    12    20    16    23    11    23     5
  Columns 31 through 40
    12     3     6     3    18     1    12     2    20    13
  Columns 41 through 50
    15     8     5     9     5     6    18    11    24    13
  Columns 51 through 60
    10     8     1     2    10     0     5     2     0     1
counter =
    26
Z =
764007273092176420933524184336236482241458595793540813005201
N =
  Columns 1 through 10
    14    12    15     6     4    14     4    21     8     7
  Columns 11 through 20
    21     4    11    16    13    15    10     4    20     6
  Columns 21 through 30
    15    13     7    13     4    20     9    14    10    15
  Columns 31 through 40
     7    12    14    11    22     8    12    10     4    12
  Columns 41 through 50
    11    20    15    26    15    23    23    13    19    11
  Columns 51 through 60
     5    20     2    14     1     3    10     4     5     4
  Columns 61 through 62
     0     1
counter =
    27
Z =
153565461891527460607638361051583532930533177754501703414045401
N =
  Columns 1 through 10
     2    10     7    15    15    15    14    17     6    22
  Columns 11 through 20
    19    10    19     5    19    10    19     4    18     0
  Columns 21 through 30
    20    12    13    22     9    20     5     6    11     2
  Columns 31 through 40
    15    17    11    18     9     9    21     8     9    13
  Columns 41 through 50
     6    11     5    17    15    21    17    15    15     4
  Columns 51 through 60
     7    14     1    13     8     5    12     1    12    10
  Columns 61 through 65
    12     5     6     0     1
counter =
    28
Z =
30866657840197019582135310571368290119037168728654842386223125601
N =
  Columns 1 through 10
     6     0    19    12    20    18    16    20    21    15
  Columns 11 through 20
     8     6    18    15     9     9    18  ...
6
Pass
 
%%
n=1;
x=1;
q=1;
y_correct = 1;
assert(isequal(whatdigit(n,x,q),y_correct))
Z =
1
init =
     1
counter =
     1
N =
     1
y =
     1