text: You should not be tackling a problem as difficult as this without having WORKED OUT the solutions to quite a few easier problems.  You are probably stuck on this one because you copied the answers to the easier ones, and learned nothing from them.  It's time to wake up.  Prolog is already difficult enough without making it even more difficult for yourself by trying to take short cuts which just leave you in a dead end like this.