# SimpleBlog

Index of all articles

## Permutationgame

Some times ago I played around with Python and Tkinter. To do something usefull I thougt about a game like Rubic’s Cube but simpler, so I came up with a sort of 2D Version.

(As I noticed later someone else has done this before, but it was really hard to find a Version of this game and since it was long time ago that I tried to find it and I don’t remember the the name I beg your pardon that I can not give you a reference. As I remember there was a 4×4 Version of this game)

My game looks like this (4×4, but you can also start with the 3×3 or 5×5):

With the arrow buttons you can move the rows and columns. The principle is that you move positions of a row or column (top and left) 1 to 2, 2 to 3, ... n-1 to n and n to 1 or vice versa (bottom and right).

The left top corner button mixes (M) the game and the right top corner button (R) brings the game back to start possition.

Here the board after a mix event:

If you start the game, there is a welcome screen where you can choose between 3×3, 4×4 and 5×5 version of the game. Simply click on one of the boards:

There is no more functionality implemented, I don’t want to sell it ;-) But there is a log text field where you can see the moves already been done. So doing the oposite will bring you back almost on the shortes path (almost, becaus the random mix sometime generates cycles or pushes the same arrow twice although it could do it with one push on the opposite side. The last sentence was for the 3×3 version.) Ok, in this version (I mean with the log window, not 3×3, but 3×3 is also no challenge) this game is not realy challenging.

But, there is a standard way to solve the puzzle, and it is realy simple if you find the way. (Its not the shortest way to solve it but you can simply write a programm that will solve it. I tried to implement the game also in ruby and wrote a solver. It had only a few lines of code. But what a shame this version of the programm got lost anywehre in the nirvana of one of my computers. I can not find it. This is not a Fermat trick!)

The real challenge will be to write a Programm that finds the shortest path. As you see in the pictures above, there are 2 corner buttons left in the bottom of the board. What about writing two python functions for this buttons? I suggest: left bottom corner: the stupid way (but be carefull, there is always a last step move chain, that is realy hard to find) and for the right bottem corner: the intelligent way (I don’t know, if there is an analytical permutation algebra out there. I’ve read a nice book about permutations: Deutsch Taschenbücher, Nr.49, Transformationen und Permutationen von Lev A. Kaloujnine und V. I. Suscanskij (Broschiert – 1986) But the only thing I recogniced was that you can proof a lot with permutation groups, but not how to calculate solutions. Ok, I’m not a mathematican only a naive one ;-) )