That does look like a lot of fun.
Okay, you inspired me to write my first Prolog program:
#
% set up the geometry
cell(1).
cell(2).
cell(3).
cell(4).
cell(5).
cell(6).
cell(7).
cell(8).
cell(9).
horizontal_adjacent(1,2).
horizontal_adjacent(2,3).
horizontal_adjacent(4,5).
horizontal_adjacent(5,6).
horizontal_adjacent(7,8).
horizontal_adjacent(8,9).
vertical_adjacent(1,4).
vertical_adjacent(4,7).
vertical_adjacent(2,5).
vertical_adjacent(5,8).
vertical_adjacent(3,6).
vertical_adjacent(6,9).
% now for shape placement
can_red(A) :- cell(A).
adjacent(A,B) :- horizontal_adjacent(A,B).
adjacent(A,B) :- vertical_adjacent(A,B).
can_yellow(A,B) :- adjacent(A,B).
can_green(A,B,C) :- horizontal_adjacent(A,B), horizontal_adjacent(B,C).
can_green(A,B,C) :- vertical_adjacent(A,B), vertical_adjacent(B,C).
can_blue(A,B,C) :- horizontal_adjacent(A,B), vertical_adjacent(B,C).
can_blue(A,B,C) :- vertical_adjacent(A,B), horizontal_adjacent(B,C).
:- use_module(library(lists)).
solution([A,B,C],[D,E,F],[G,H],I) :-
can_green(A,B,C),
can_blue(D,E,F),
can_yellow(G,H),
can_red(I),
is_set([A,B,C,D,E,F,G,H,I]).
This doesn't take symmetries into account. I haven't decided yet how much I can tell the program explicitly (e.g., put the green thingy on the bottom) without it being cheating.
Here's the first result I got:
?- solution([A,B,C],[D,E,F],[G,H],I).
A = 1,
B = 2,
C = 3,
D = 4,
E = 5,
F = 8,
G = 6,
H = 9,
I = 7
I could constrain the green piece by saying, e.g.,
?- solution([1,2,3],[D,E,F],[G,H],I).
And similarly for the other pieces.
The interesting parts of the program are the can_
color rules. In the solution
rule, I use is_set
to make sure I haven't put two pieces in the same space. (A set is a list with no duplicated items.)
P.S. It's your class, but you pushed one of my buttons with "Let's use Snap! to..." Curriculum writers all do this, and I find it terribly dishonest, and I bet kids do too. Not quite as bad as "Let's play 52 Pickup," but it similarly suggests a symmetry of roles that just isn't the case.
P.P.S. I'm sure any minute now Ken will tell me how I should have written it! :~)