Please refer to this page for information on how to work on your assignment.
Although historically Euclid's Algorithm was implemented by substracting the smaller number from the larger one, the famous version of the algorithm has one improvement: it computes the remainder of the division of two numbers instead of their difference. The task is to update the below program accordingly and to do some further changes of the input-output behaviour.
Test the currently implement algorithm with inputs 1000 and 2. Scroll down the window to inspect the output.
Read the program and understand what is going on. Then do the following changes:
x = x - y;
and
y = y - x;
in the source code.
x
is different from y
. But
since the remainder operation does not make x
and
y
equal, but one of them to 0, you have to check that both
x
and y
are greater than 0.
endtext
.
This test has to ask whether x == 0
or y == 0
but not whether x == y
.
"(x+y)"
instead of
x
. Note that you need the brackets since otherwise
JavaScript would not use the sum but just the concatenation of the
printout of the numbers. So for instance 37 + 12 would give 3712
instead of 49.
endtext
variable plus a phrase which tells to click
"OK" for continuing the program. So write something like:
do … while(confirm(endtext + " Press 'OK' to continue"));
Run the whole program and test it. Compare it on the inputs 1000 and 2 with the old program. Scroll down to check the protocol output printed during the computation. Is it faster than the old one?
You can hand in the program after checking its correctness by showing it to the lecturer.