The puzzle consists of 9 quadratic cards, each with the half
(front or back) of a figure at its edges. These figures have
different colors and fill patters.
The game is solved when all cards are assembled to a 3x3 square of
cards, showing ten whole (front and back), consistently
colored/patterned figures.
Here is an image
of such a puzzle.
I was able to manually find one solution, but the packaging promised
two of them, so I wrote a program to find it for me, using a
brute-force attempt...
#include <algorithm>
#include <iostream>
// 9 cards with 4 figures each.
// The two characters describe color and part of the figure.
char * cards[9][4] =
{
{ "BB","OB","GF","NF" },
{ "GB","OB","GF","NF" },
{ "BF","OF","GB","NB" },
{ "BF","NF","OB","GB" },
{ "BF","OF","BB","NB" },
{ "GF","OF","BB","NB" },
{ "NB","OB","BF","GF" },
{ "BF","OB","NB","GF" },
{ "BF","OF","GB","NB" }
};
// Order of cards (initial permutation)
int order[9] = { 0,1,2,3,4,5,6,7,8 };
// Rotation (0..3) of each card
int rotate[9];
// Test if an edge fits
inline bool edge_fits(int card1,int card2, int edge)
{
char* cmp1 ( cards[order[card1]][( edge + rotate[card1]) & 3] );
char* cmp2 ( cards[order[card2]][((edge^2) + rotate[card2]) & 3] );
return (cmp1[0] == cmp2[0]) && (cmp1[1] != cmp2[1]);
}
int main(void)
{
do
{
// Display current permutation on stderr
std::cerr << "Permutation: ";
for (int j = 0; j < 9; ++j)
std::cerr << order[j] << " ";
std::cerr << std::endl;
// We need an 18 bit value to iterate all rotations (2 bits for each card)
for (int j = 1 << 18; --j >= 0 ;)
{
// Split the counter into 9 values 0..3
for (int k = 0; k < 9; k++)
rotate[k] = ( j >> (k + k) ) & 3;
// Is it solved ?
if (edge_fits(0,1,1) && edge_fits(0,3,2) &&
edge_fits(1,2,1) && edge_fits(1,4,2) &&
edge_fits(2,5,2) &&
edge_fits(3,4,1) && edge_fits(3,6,2) &&
edge_fits(4,5,1) && edge_fits(4,7,2) &&
edge_fits(5,8,2) &&
edge_fits(6,7,1) && edge_fits(7,8,1))
{
// Tell me how
std::cout << "Solution: ";
for (int k = 0; k < 9; k++)
std::cout << order[k] << " [" << rotate[k] << "] ";
std::cout << std::endl;
}
}
}
// Again, with the next possible arrangement of cards
while ( std::next_permutation(&order[0],&order[9]) );
// It takes some time until this point is reached ;-)
return 0;
}
|
|