Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Maple Program (a) Write a procedure that will take as input a positive integer n

ID: 3789175 • Letter: M

Question

Maple Program

(a) Write a procedure that will take as input a positive integer n and whose output will be the list [c[0], c[1], . . . , c[10]] where c[i] is the number of times that i appears in the list genseq(n) where genseq is as described in Problem 3. Test the procedure for n = 100, 1000 and 10000. Do the numbers 0, 1, . . ., 10 appear to be equally distributed?

(b) In the procedure genseq replace 7*i mod 11 by 8*i mod 22. Then repeat the instructions in part (a) with [c[0], c[1], . . . , c[10]] replaced by [c[0], c[1], . . . , c[21]]. Do the numbers 0, 1, . . ., 21 appear to be equally distributed?

problem 3 as mentioned:

genseq:=proc(N)
local i, L;
L := NULL;
for i from 1 to N do
L := L, (7 * i) mod 11;
end do;
return [L];
end proc:
genseq(110);genseq(11);

Explanation / Answer

PART A :

------------

Let me state the procedure first and then i can explain using examples.

Let the name of the procedure be "gencountList"

I have given comments between /* */ . They are given just for understanding.

Let's first start by understanding "genseq" procedure.Let's undersatnd following line

L := L,(7 * i) mod 11;

Let us suppose we are going to calculate value of c[1] i.e number of times " (7 * i) mod 11 " evaluates to "1"

Now which numbers when divided by "11" gives 1 as remainder .
"1 , 12 , 23, 34, 45 , 56, 67...."

Above values are possible values of (7*i), hence they must be divisible by 7. Also note that for us max. value of (7*i) is (7*N).

Now generating this sequence is simple " (1) , (1 + 11) , (1 + 11 + 11) , (1+ 11 + 11 +11) ... "


Hence for each "i" the sequence would be " (i) , (i + 11) , (i+ 11 + 11) ... " . It's just that they should be divisible by 7 and must be less than
(7 * N).

With the above idea we have the following procedure.


gencountList:=proc(N)
   local i,j;
   /*Lets assume c to be an array of size 11 with each element initialised with value 0 */
   local c[11] = {0,0,0,0,0,0,0,0,0,0,0};
  
   /* We will calculate the count for each "c[i]"*/
   for i from 0 to 10 do
       j := i;
/*Generate the sequence for each "i" and increment c[i] if the value is divisible by 7 */

while j <= (7*N) do
      
           if ( (j % 7) == 0)
           c[i] := c[i] + 1;
          
           j := j + 11;
       end do;
   end do;
   /* while calculating value for c[0], for j=0 "(j%7)" always evaluates to "0" so we need to decrement that*/
   c[0] := c[0] - 1;
   return c;
   end proc;
  

Now lets test for N=100
-----------------------
Following is the sequence calculate using "genseq "
  
7,3,10,6,2,9,5,1,8,4,0,7,3,10,6,2,9,5,1,8,4,0,7,3,10,6,2,9,5,1,8,4,0,7,3,10,6,2,9,5,1,8,4,0,7,3,10,6,2,9,5,1,8,4,0,7,3,10,6,2,9,5,1,8,4,0,7,3,10,6,2,9,5,1,8,4,0,7,3,10,6,2,9,5,1,8,4,0,7,3,10,6,2,9,5,1,8,4,0,7
  
c[0] : 9
c[1] : 9
c[2] : 9
c[3] : 9
c[4] : 9
c[5] : 9
c[6] : 9
c[7] : 10
c[8] : 9
c[9] : 9
c[10] : 9


Now lets test for N=1000
------------------------
c[0] : 90
c[1] : 91
c[2] : 91
c[3] : 91
c[4] : 91
c[5] : 91
c[6] : 91
c[7] : 91
c[8] : 91
c[9] : 91
c[10] : 91


Now lets test for N=10000
-----------------------------------
c[0] : 909
c[1] : 909
c[2] : 909
c[3] : 909
c[4] : 909
c[5] : 909
c[6] : 909
c[7] : 910
c[8] : 909
c[9] : 909
c[10] : 909

PART B :

------------

Lets replace L := L, (7%i) mod 11   by L := L, (8%i) mod 22

Let us test for N = 100

------------------------------

c[0] : 9
c[1] : 0
c[2] : 9
c[3] : 0
c[4] : 9
c[5] : 0
c[6] : 9
c[7] : 0
c[8] : 10
c[9] : 0
c[10] : 9
c[11] : 0
c[12] : 9
c[13] : 0
c[14] : 9
c[15] : 0
c[16] : 9
c[17] : 0
c[18] : 9
c[19] : 0
c[20] : 9
c[21] : 0

Let us test for N = 1000

---------------------------------

c[0] : 90
c[1] : 0
c[2] : 91
c[3] : 0
c[4] : 91
c[5] : 0
c[6] : 91
c[7] : 0
c[8] : 91
c[9] : 0
c[10] : 91
c[11] : 0
c[12] : 91
c[13] : 0
c[14] : 91
c[15] : 0
c[16] : 91
c[17] : 0
c[18] : 91
c[19] : 0
c[20] : 91
c[21] : 0

Let us test for N = 10000

----------------------------------

c[0] : 909
c[1] : 0
c[2] : 909
c[3] : 0
c[4] : 909
c[5] : 0
c[6] : 909
c[7] : 0
c[8] : 910
c[9] : 0
c[10] : 909
c[11] : 0
c[12] : 909
c[13] : 0
c[14] : 909
c[15] : 0
c[16] : 909
c[17] : 0
c[18] : 909
c[19] : 0
c[20] : 909
c[21] : 0

Hope that helps !!