Thursday, February 09, 2006

OK, one more day without me. . . We will talk next week about the things you have been doing and applying them. Today I want you to open up Guido again. I have a new project for you. Open the file "binaryAdd.wld" from the "python\gvr" folder.

This world gives two binary numbers (along 2nd and 3rd avenues). You need to write a program that will add these binary numbers and place the result on first avenue with no other beepers left. When done, place guido on the east side of the wall. After completing the program your answer should be: 110010100

When you have the program done, you can test it by doing this addition problem:
1101001
1001011

You should get this:
10110100

Once you get that, try changing your world so it will actually add more than two binary numbers (move the wall along the north.) You may have to carry multiple times. . .

If you are having troubles, here are a couple of hints. You will need to highlight the next section in order to read them. (In case you want to try without any accidental seeing of my algorithm.)

Hint 1:


















Hint 2:





OK, that was fun! Here is a real hint!

In order to do this I would create a couple of different stages. First I would take care of adding the columns, then of going through and taking care of any carrying.

If you can't get it from there, go ahead and look at hint 3.


Hint 3:

To add the columns you will want a definition that simply goes up collecting all beepers, then places them back at the bottom of the column. Do this until you reach the westward wall.

Hint 4:



Remember in binary you can only have a zero or a one. If any spot has a 2 it needs to be carried forward (leaving zero behind). Start at the far right, and check each spot to see if it needs to carry. (This can be another definition inside of a while loop.)

No comments:

The OFFICIAL Dilbert Widget