![]() This means that when I find a solution I have a list of all the moves I made to get there. StoreBoards = - I want to keep track of the moves I have made en route to a solution. This allows me to store the co-ordinates of each hole on the board alongside the information explaining if there is a peg or not at that location. This would be an ideal puzzle to solve using Python.įirst of all I am going to show you my program in its entirety, and then take you through the programming of it line by line.įrom _future_ import print_function #Allows python3 use of print() import copy import datetime #Global Constants WIDTH = 7 HEIGHT = 7 CORNERSIZE = 2 #Global Variables gameBoard = - I am going to store my board in a dictionary. It's one of those things I have played with every so often, but never really tried to work out. My son started to play with Pin Solitaire at a friends house one day, and I gave him a hand explaining the game. More for my knowledge than anything else. It turned out just learning how to actually do the Rubiks cube is much easier than you think! However, in the process, I had learnt a little about Breadth-first search and Depth-first search, and thought it would be great to solve a problem using one of these methods. It turns out the god number is 20.Īt this point I put the Python solution for the Rubiks cube aside, at least temporarily. This is the minimum number of moves needed to solve a Rubiks cube from any position. ![]() ![]() Finally I realised Google had thrown their weight behind the puzzle, and determined the 'god' number. and then I started to research how difficult a task it really was. I, naively, thought it would be a simple matter to churn through all the available options until the program stumbled across the solution. One of my earlier forays into solving a puzzle using Python was to solve the Rubiks cube. There is something hugely satisfying about finding the solution to a puzzle. I am a huge fan of puzzles, and think that my love of programming comes from that enjoyment.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |