Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Weird useless algorithm

Name: Anonymous 2015-01-08 3:56

How to subtract the smallest of two integers from the greater one, in a system that supports only addition, equality comparisons and conditional jumps:

The numbers are A and B.
If A=B, return 0 as the answer.
Define three numeric variables a, b and c of the same type as A and B.
Let a=A, b=B and c=0.
Now let c=c+1, a=a+1 and b=b+1.
If either a=B or b=A, go to the next line. Otherwise, go to the previous line.
Return c as the answer.

The algorithm is not mine, by the way. It's anonymous.

Name: Anonymous 2015-01-09 4:01

>>10
Have you tried them on the specified machine?

>>1 is incorrect for the case a = 0, b = 0.
>>7 is incorrect for using operations not present on the specified machine.
The commentary in >>10 is incorrect for italicizing subtrahends inappropriately, see this sentence for an example of correct application of italics to a term.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List