Answer the question
In order to leave comments, you need to log in
How to generate a sequence like "0, 1, -1, 2, -2, 3, -3..." in Prolog?
It is necessary to generate elements of such a sequence "0, 1, -1, 2, -2, 3, -3 ...". I just got to this, but the result is crashing:
num(1).
num(X) :- num(Y), X is -Y, X < 0.
num(X) :- num(Y), X is -Y + 1, X > 0.
?- num(X).
X = 1 ;
X = -1 ;
ERROR: Out of local stack
Exception: (1,763,389) num(_6002) ?
Answer the question
In order to leave comments, you need to log in
Here the last answer explains why it doesn't work and shows solutions:
https://stackoverflow.com/questions/19979548/predi...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question