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-16 6:16

def abs(a, b):
c = 0
while True:
if (a + c) == b:
return c
if (b + c) == a:
return c
c += 1

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