GithubHelp home page GithubHelp logo

the_magic_triangle's Introduction

The Magic Triangle

This project presents a simple solver for an old puzzle published by Heye puzzle, which I recently came across. Apparently, the game is available in different flavors (triangles, squares).

Snoopy - The Magic Triangle, Heye

The version of puzzle used here consists of nine equilateral triangles with lower and upper parts of figures printed on them. The objective is to form a large triangle in such a way that the shapes and colors of the parts of the figures on neighbouring triangles match.

Approach

The following triangles come with the game:

                / \                 |                 / \    
               /   \                |                /   \   
              /HO BW\               |               /a   b\  
             /       \              |              /   0   \ 
            /    HW   \             |             /    c    \ 
            -----------             |             ----------- 
          / \    HW   / \           |           / \    c    / \     
         /   \       /   \          |          /   \   1   /   \    
        /BG HG\BG HG/HO BW\         |         /a   b\b   a/a   b\   
       /       \   /       \        |        /   2   \   /   8   \ 
      /    HO   \ /    BO   \       |       /    c    \ /    c    \ 
      ----------- -----------       |       ----------- ----------- 
    / \    BW   / \    HO   / \     |     / \    c    / \    c    / \     
   /   \       /   \       /   \    |    /   \   3   /   \   6   /   \    
  /BO BG\BG HO/BO HO\BG HG/BW BG\   |   /a   b\b   a/a   b\b   a/a   b\   
 /       \   /       \   /       \  |  /   4   \   /   5   \   /   7   \ 
/    HO   \ /    BG   \ /    HW   \ | /    c    \ /    c    \ /    c    \ 
----------- ----------- ----------- | ----------- ----------- ----------- 

All triangles (cf. the image above)    Indices of the triangles and sides

where

  • HO -- head orange
  • HG -- head green
  • HW -- head white
  • BO -- body orange
  • BG -- body green
  • BW -- body white

The solver uses backtracking in order to find the solutions. Given a set containing nine triangles, a total of 362880 permutations exist to form a large triangle. For each of these (spatial) permutations, every triangle can be rotated in one of three ways (0, 120, 240 degrees), which amounts to 19683 possible combinations. That means, all in all approximately 7.1e9 different possible configurations exist. Backtracking helps to discard most of these (possible but wrong) configurations.

When evaluating one of the configurations above, nine pairs of neighboring triangles are tested. A test is valid if one of the neighboring triangle has a head of figure printed on it while a body printed on the other triangle and both are of the same color.

According to the publisher of the game, two solutions exist. The solver will find six solutions, though. That is because each of the two solutions can be rotated into three different position.

Usage

Just run

$ python ./the_magic_triangle.py deck_of_cards.csv edge_matches.csv

For the impatient, the solutions can also be found here.

the_magic_triangle's People

Contributors

enpe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

ferenc- basti564

the_magic_triangle's Issues

Help please!

Sehr geehrter Herr Plath,

ich kann leider das Programm nicht zum Laufen bringen, um die Ergebnisse bzw. die Funktionsweise des Programms nachvollziehen zu können. Wie the magic triangle als Spiel funktioniert ist mir klar und ein paar Lösungsansätze für die Programmierung habe ich auch.

Ich habe leider nur noch sehr wenige Erfahrung in der Programmierung und manche Algorithmen beherrsche ich noch nicht.

Meine Idee ist nicht Ihr Programm eins zu eins ohne weiteres zu übernehmen, sondern dieses zu verstehen, Code-Teile anzupassen und auch dabei vieles neues zur Programmierung lernen.

Ich hoffe Sie können mir helfen, das Programm zum laufen zu bringen, um Ihre Lösung besser zu verstehen.

Ich bedanke mich im Voraus!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.