I have to write a predicate called stepup(L, Z, X)
, where L
is a list and Z
and X
are the integers. It should return true
if the Z
can be stepped into X
using legal steps given by the user in the list.
For example
stepup([7, 12, 19], 6, 32)
should return true
since 6 + 7 + 7 + 12 = 32
starting number should always be Z
(here 6) and the rule should only use steps from the list. The rule should work for all sizes, (Z, X)
are always positive.
I started with this
step([V|S],A,D):-
sum is A+V,
(sum=A -> write('true')
; step(S,sum,D).
but not sure how to proceed
Maybe this helps:
Let's put it to use!
Note that the redundant answers in the second query are due to the different ways to step up from
6
to32
using steps[7,12,19]
.