I am trying to write a program that describes a scenario where a bunch of blocks are stacked on top of each other, and on 4 different "places" this is what I have so far:
block(a).
block(b).
block(c).
block(d).
block(e).
block(f).
block(g).
place(p1).
place(p2).
place(p3).
place(p4).
on(a, p1).
on(d, a).
on(g, d).
on(f, g).
on(b, p3).
on(e, b).
on(c, p4).
/*Simple Rules */
under(X, Y) :- on(Y, X).
between(X, Y, Z) :- on(Y, X), under(Z, X).
alone(X) :- <---- need help here
/* Recursive Rules */
bottom(X, Y) :- under(X, Y).
bottom(X, Y) :- under(Z, Y), bottom(X, Z).
/* List Processing */
head([X|_], X).
tail([_|T], T).
/* Print out the elements of a list */
traverse([]).
traverse([X|T]) :- print(X), nl, traverse(T).
stacked([X], Y) :- on(X, Y).
stacked([X], Y) :- on(Z, Y), stacked(X, Z). <----- and here
len(X, [Y]) :- ???
len(X, [Y]) :- ???
-------------------------------------------------------------------------------------
The alone(X) rule is supposed to be true if it is the only block that is stacked on a place, but I'm not sure how exactly to write this.
The other problem I'm having is with lists, stacked is supposed to return a list of all the blocks stacked on Y, and len is supposed to return X where X is the number of elements in list Y. I just have no idea what the syntax is here or how to get the query to return a whole list instead of just 1 value. Prologs website is down right now too apparently so any help would be greatly apprecatiated
block(a).
block(b).
block(c).
block(d).
block(e).
block(f).
block(g).
place(p1).
place(p2).
place(p3).
place(p4).
on(a, p1).
on(d, a).
on(g, d).
on(f, g).
on(b, p3).
on(e, b).
on(c, p4).
/*Simple Rules */
under(X, Y) :- on(Y, X).
between(X, Y, Z) :- on(Y, X), under(Z, X).
alone(X) :- <---- need help here
/* Recursive Rules */
bottom(X, Y) :- under(X, Y).
bottom(X, Y) :- under(Z, Y), bottom(X, Z).
/* List Processing */
head([X|_], X).
tail([_|T], T).
/* Print out the elements of a list */
traverse([]).
traverse([X|T]) :- print(X), nl, traverse(T).
stacked([X], Y) :- on(X, Y).
stacked([X], Y) :- on(Z, Y), stacked(X, Z). <----- and here
len(X, [Y]) :- ???
len(X, [Y]) :- ???
-------------------------------------------------------------------------------------
The alone(X) rule is supposed to be true if it is the only block that is stacked on a place, but I'm not sure how exactly to write this.
The other problem I'm having is with lists, stacked is supposed to return a list of all the blocks stacked on Y, and len is supposed to return X where X is the number of elements in list Y. I just have no idea what the syntax is here or how to get the query to return a whole list instead of just 1 value. Prologs website is down right now too apparently so any help would be greatly apprecatiated