How ancient Egyptians multiplied two numbers.
One method used by the ancient Egyptians to multiply two numbers was discovered in the Rhind Mathematical Papyri written in approximately 1550 B.C. and discovered in Thebes in 1650. It inspired how binary computers could perform such arithmetic as many had no multiply operator until the late 1970s.
The algorithm requires taking the first number and repeatedly integer dividing it by two until the number equals one, writing each new number in a list. The second number is then multiplied by two the same number of times with the results recorded in a second list. A number is removed from the list if the number in the first column is even. The sum of the remaining numbers in the second column is the result of the multiplication.
13 * 28 = 364
These objectives get progressively harder. Attempt as much of the program as you can in the order presented below. Remember to use a comment to describe a subpprogram, selection or iteration.
Use this boilerplate code as a starting point:
4 marks
Enter the first number: 13
Enter the second number: 28
5 marks
Continuing code in the `mul` subprogram:
3 marks
Continuing code in the `mul` subprogram:
3 marks
Continuing code in the `mul` subprogram:
4 marks
Enter the first number: 13
Enter the second number: 28
364
3 marks
Maximum mark: 22
If you score less than 17 you need more practice at levels 1-6 before you continue to the next level.
Use these resources as a reference to help you meet the success criteria.
Run the unit tests below to check that your program has met the success criteria.
Enter the first number: 82
Enter the second number: 91
7462
Enter the first number: 18
Enter the second number: 63
1134