Solving Professor Popalop’s puzzles in Prolog

This puzzle was in my daughter’s Dandy: and I thought it would give me an opportunity to experiment with Prolog, which I’d been meaning to do for a while. I used SWI-Prolog. Structure of the puzzle We’ll represent a block of nine boxes as a list. A box is the expression X/Y/C, meaning that creature type C occupies location X/Y, where the top-left box is 1/1. We’ll have a fragment similar to Bs = [1/1/_, 1/2/_, 1/3/_, 2/1/_, 2/2/_, 2/3/_, 3/1/_, 3/2/_, 3/3/_] Our goal is to find which creature can go in each box. The different types of creature Every box must have a creature in it. box_has_creature(_/_/p). box_has_creature(_/_/h). box_has_creature(_/_/b). We’ll use the variable name ‘Bs’ throughout to mean

Continue reading