Skip to content

Welcome Sites Tools Teacher guide Help
  You are not logged in Join

Log in

Bugging and debugging

Created by Sofia   -   Topic Group: Sequences   -   Created: 12-11-04   -   Modified: 19-02-05




Bugging and debugging

(a webreport based on the comments Teddy was making while working on ADD_1, ADD_UP and the FACTORIAL robot)

For warming up Jenny asked me to construct the ADD_1 and the ADD_UP robots. It was easy. We had done such robots last year but this time she wanted me to connect them. So, to run the ADD_UP robot I put the nest of ADD_1 in the first cell, 1 – in the second and another nest – in the third.

Bug #1

I expected to see the terms of the sequence:

1, 3, 6, 10,…

in the second cell since they were the consecutive sums of the natural numbers:

1, 1+2, 1+2+3, etc.

 But to my surprise the numbers were instead;

1, 2, 4, ….

So I realized that the first number in the second cell should be 0, not 1.

Then I retrained the ADD_UP robot so as to generate the numbers:

1, 1, 2, 6, 24, …

Instead of adding this time the robot should multiply the natural numbers coming from the nest in the first cell. I’ll call it MULT_UP for now.

Bug #2

First I gave the number 1 to the second cell. Then I erased the number from the first cell (with the nest) and replaced it by “*1”. Thus I replaced “1” by “*1” and I thought that the robot would replace the number in the nest with the “*” in front. But of course it replaced any further number with “*1”.

Bug #3

Then I figured out that I should add “*” in front of the number (whatever it would be). So I used the arrow key to put the cursor in front of the number and pressed the “*” key.

To accelerate the process I left the house so as not to “embarrass” the robot and came back in a while. The numbers in the first two cells were:

1142 (in the nest) and 427404 – in the second one.

I showed this result to Jenny and she asked me if the number in the second cell (427404 in my case) was divisible by 3.

Of course it was – its figures when added up gave 21 which itself is divisible by 3.

Then she asked me: What about 7? First of all the rule for divisibility to 7 is disgusting and second of all - I don’t know it… Then she said: What about 1113? I have to check, I said but Mitty was sure that it is not divisible. Then Jenny without checking said: If it is not divisible by 1113 then your robot is not working properly.

How could she be so sure? She saw the start of my robot and she looked happy with what she saw.

Then she asked again: How did you get this number? Did it fall from the sky? If you were playing outside and I had written this number on the board for you to check if it is divisible by 3, 7 or 1113 you could apply the rules for divisibility or a direct division. But now you better think about the process behind it.

Then it dawn on me! Of course the number 427404 should be divisible by 1113 because the ADD_1 robot had already given 1113 to MULT_UP. Even more, any number in the second cell should be divisible by all the natural numbers from 1 to the current number in the nest minus 1. For example if we see the number 10 in the nest (the first cell) the number in the second cell should be equal to 1*2*3*4*5*6*7*8*9.

And since 1113 is smaller than 1141 it should divide 427404 which (according to the way I taught the robot) should be equal to 1*2*3…*1141.

But there was something strange – no wonder Jenny thought this product should be much bigger than 427404. For a moment Mitty and I thought that we might have done a mistake with the operation and we check if the number 427404 satisfies the formula for the numbers in the first sequence– N(N+1)/2, i.e. if 427404 is equal to 1140*1141/2. But this was not true either, so I decided to check the work of the robot more carefully… What I found was that it worked correctly only till 9. After the number in the nest would have more than 1 digit, e.g. 10, the second cell would get “1*0” instead of “*10” and this was treated as 1 (or as “something multiplied by 0 plus 1”, as Mitty commented) and added to the current number. We experimented a little bit with the result of putting the “*” sign in front of the last digit but didn’t reach a consensus. At this point it was more important for me to debug my robot. So I pressed the “*” sign after the number and realized that TT puts it immediately in front of it and thus multiplies it by the current number in the second cell. This time the robot seemed to work O.K. and the numbers in the second cell were growing very fast.

Jenny asked me what was the reason I hadn’t realised immediately that a number in the second cell is divisible by a concrete number less than the number in the nest. I wasn’t sure but maybe because the number was 3 and I knew another way to check it. Sometimes I wonder if I am genius or dumb…