And for a mental break after a few weeks of living swamped-in-code, here’s One Tough Puzzle.

I spent a good deal of time writing programs to solve puzzles – in Java and PROLOG – for my AI Bachelor’s, and the last several solving problems that are harder and more useful to solve – in php and SQL. So it’s come to this, I’m using today’s tools to solve yesterday’s non-problems.

Here’s a hard-coded SQL script to solve this puzzle. It’s not terrifically extensible beyond 9 glossy pieces, but it is proof that SQL can do it given the chance.

CREATE TABLE tiles (id serial, one text, two text, three text, four text);

INSERT INTO tiles (one, two, three, four) VALUES


SELECT as middle, as cw1, as cw2, as cw3, as cw4, as cw5, as cw6, as cw7, as cw8

FROM tiles AS mi

JOIN tiles AS e1 ON not in ( AND (( = e1.three) OR ( = e1.four))
JOIN tiles AS e2 ON not in (, AND ((mi.two = e2.three) OR (mi.two = e2.four))
JOIN tiles AS e3 ON not in (,, AND ((mi.three = OR (mi.three = e3.two))
JOIN tiles AS e4 ON not in (,,, AND ((mi.four = OR (mi.four = e4.two))

JOIN tiles AS d1 ON not in (,,,, AND
(((e1.three = AND (d1.four = OR
((e1.three = d1.two) AND ( = e2.four)) OR
((e1.two = d1.three) AND (d1.two = e2.four)) OR
((e1.two = d1.four) AND (d1.three =

JOIN tiles AS d2 ON not in (,,,,, AND
(((e2.three = AND (d2.four = e3.two)) OR
((e2.three = d2.two) AND ( = e3.three)) OR
((e2.two = d2.three) AND (d2.two = e3.three)) OR
((e2.two = d2.four) AND (d2.three = e3.two)))

JOIN tiles AS d3 ON not in (,,,,,, AND
(((e3.four = AND (d3.four = e4.two)) OR
((e3.four = d3.two) AND ( = e4.three)) OR
(( = d3.three) AND (d3.two = e4.three)) OR
(( = d3.four) AND (d3.three = e4.two)))

JOIN tiles AS d4 ON not in (,,,,,,, AND
(((e4.four = AND (d4.four = OR
((e4.four = d4.two) AND ( = e1.four)) OR
(( = d4.three) AND (d4.two = e1.four)) OR
(( = d4.four) AND (d4.three =