:-dynamic(on/2). % allows us to retract facts defined in a file.
on(c,f).
on(d,g).
on(d,f).
on(b,d).
on(a,c).
on(a,d).
on(e,floor).
on(f,floor).
on(g,floor).
on(c,e).

clean :-
	on(Block,_), \+on(_,Block),
	format('Remove ~w\n', Block),
	retractall(on(Block,_)), clean, !.
clean :- \+on(_,_).

shuffle(_) :- retractall(on(_,_)), L = [on(a,c), on(a,d), on(b,d), on(c,e), on(c,f), on(d,f), on(d,g), on(e,floor), on(f,floor), on(g,floor)],
    permutation(L,P), !, member(On, P), assert(On), fail.
shuffle(R) :- findall(on(A,B), on(A,B), R).
