Mark Gritter (markgritter) wrote,
Mark Gritter
markgritter

Tantrix

Sarah, Jeff, and the niecelets gave me Tantrix for Christmas. It is a game about making loops with hexagonal tiles (each of which has three colored lines.)

On a single hexagonal tile a line may take one of three distinct paths--- either straight across, to one of the adjancent sides, or one of the "opposite" sides. These correspond to a change in direction of 0 degrees, 60 degrees, or 120 degrees. A complete loop must have bends that total to a multiple of 360 degrees. So, for a given combination of tiles, we should be able to limit the search for a loop by enumerating what possibilities of "left turns" and "right turns" the solution must have. (Of course, two 60 degree turns end up in a different location than a single 120 degree turn.)

I think that for this puzzle restrictions to exactly 360 degrees are sufficient--- the solution cannot loop (and it is obvious at least for small numbers of tiles that summing to zero will not produce a solution.) But right now neither my geometric intuition nor algebraic skills are sufficient to show that this is so.

3 tiles: 3x 120 only
4 tiles: 2x60 + 2x120 only, all right hand turns
5 tiles: 4x60 + 1x120; or 60 + -60 (left hand turn) + 3x120; or 5x120 + -120

Given this model of the problem it is trivial to write python code which returns all the possible curves. If you have python 3.1+ then builtins are all you need; otherwise you will have to copy the code from the manual. This version shows all curves for a given number of tiles, while the Tantrix problems are simpler since there's a fixed set of tiles!

tileSet = [ 60, -60, 120, -120 ]

def cycles( numTiles ):
    return filter( lambda x : sum( x ) == 360,
                   combinations_with_replacement( tileSet, numTiles ) )
Tags: programming, puzzles
Subscribe
  • Post a new comment

    Error

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 3 comments