Professorspillet (Python)

https://github.com/koffespriv/theProfessorGame

“Professorspillet” is a Danish game of head and tails where the goal of the game is to arrange all the 16 tiles so all upper and lower body’s match.

The creators of the game did not bother to be very exact with respect to the labeling. According to this link http://www.madalgo.au.dk/~gerth/dADS1-04/professor-loesninger.html there are 23 solutions, and if you consider that two of the pieces are identical and the whole board may have four orientations then there are 184 valid solutions. The box states that there are two correct solutions and about one million combinations. Not considering the orientations and duplicate pieces, the number of combinations are 24!*4 = 2.48e+24, 18 orders of magnitude more than the came claims.

As a child I tried many times to solve this game by hand to no avail. In 2011 I wrote a C++ solver to finish this game once and for all.  This implementation is briefly described here https://skoien.org/?page_id=135

This page is dedicated to my 2019 Python implementation. The code is available here: https://github.com/koffespriv/theProfessorGame and I invite anyone to provide feedback there and submit pull requests.

The implementation is fairly simplistic, as I desired that the code to a large extent reflected the physical tiles and 4*4 board layout. The sides, tiles and the deck (of tiles) are all represented by separate classes. The solver iterates through the board starting at the top left corner p1,1. It places tile t1 there and checks if it is placed valid in relation to the tile above and to the left. Since there are no tiles above or to the left of p1,1 this will always be valid. A tile t2 is then placed to the right of the first one on p1,2. Validity is checked, and if not valid this tile is rotated clockwise. If valid a new tile is placed, if not t2 is replaced with t3 and the process is repeated.

Once a valid solution is found, a visualization of the board can be displayed and the results are also written as vector graphics to solutions/ According to the above link, there are 23 unique solutions (since two tiles are identical and the entire board can be rotated there are 184 solutions). This implementation does not filter results and gives all 184 solutions.

If you want to see all solutions, please download this PDF: