:-dynamic(on/2). % allows us to retract facts defined in a file.
on(a,c).	on(c,e).	on(e,floor).
on(a,d).	on(c,f).	on(f,floor).
on(b,d).	on(d,f).	on(g,floor).
			on(d,g).

% on(c,a). % loops with this present!

removable(B) :- \+on(_,B).

remove(B) :-
	removable(B),
	retractall(on(B,_)),
	format('Remove ~w\n', B).
	     
remove(B) :- on(Above,B), remove(Above), remove(B).

clean :- on(B,floor), remove(B), clean, !.
clean :- \+on(_,_).  % w/o this, fails when cleaning.
