As you can see from my predicate iterate, I am repeating Z is X-3
and Z is X-2
, the scenarios are different if the value is 0 or greater than 0. thus why the duplicates,
Was wondering if there was a way round this
iterate([], []). %Nothing to change
iterate([1|T], T).
iterate([X|T], [Z|T]) :- % Change only the headT
( Z is X - 3
;
Z is X - 2
),
Z>0 .
iterate([X|T], T) :- % Change only the head
( Z is X - 3
;
Z is X - 2
),
Z is 0 .
iterate([X|Xs], [X|Ys]) :- %Keep the head and change something later
iterate(Xs, Ys).
~ is X - 3
andZ is 0
, then the condition can be written simply asX = 3
. Thus the whole branch can be written asiterate([X|T], T) :- (X = 3 ; X = 2).
, or perhaps even simpler:iterate([3|T], T). iterate([2|T], T).
which you seem to be already doing initerate([1|T], T).
. But it's really difficult to understand the desired result. \$\endgroup\$ – wvxvw Oct 24 '17 at 9:30