Should not be too difficult.įor one thing, there is no need to press on any switch more than once. I think you should be able to figure out an algorithm for this. It returns the switches that you need to press to turn all the lights off. You give it the height and width of the switch array, and the initial state a row at a time. Overall, this solves the problem in O(n^3) operations. You can substitute the value for x_n you get from this into the earlier equations. Now, E_n is an equation which only contains x_n. Add E_1 to every other unnamed equation with an x_1 in it.Specifically, here's the Gaussian elimination algorithm in arithmetic modulo 2: For example, to get rid of x_1 in the 2nd equation, simply add the first equation to it. Because you're working in arithmetic modulo 2, it's actually a bit easier than simultaneous equations over real numbers. Now you can use gaussian elimination to solve this set of simultaneous equations. It's basically encoding the rule about which switches cause a particular light to toggle. Now, you can write down some equations (in arithmetic modulo 2) that the solution must satisfy. Let's say you're solving a 3x3 problem, and the variables are set up like this: x_1 x_2 x_3 , x_n be variables corresponding to whether you press the n'th button as part of the solution, and let a_1. There's a well-known method for solving this problem. # prints puzzle-board state at end of loop iteration # randomly generates number, flipping random switches # for counting the iterations within the loopĪns = a1 and a2 and a3 and b1 and b2 and b3 and c1 and c2 and c3 Print "What's ON/OFF? (type 0 for OFF, 1 for ON)" Switches 'x' to 1 if it's a 0 and vice-versa It's been about an hour, still hasn't found a solution, it is currently on its ~92,000,000th iteration. P.S.: While I was signing up for a StackOverflow account and typing this message, my computer has been running this program in the background to find a solution. It then enters a loop, randomly toggling the puzzle-board's switches until they're all ON. I intended to allow the user to input the current state of the puzzle-board with the first 9 raw_inputs. The only thing I could thing of was to have the computer store the puzzle's states in a list or dictionary, assisting the program by skipping over those stored states, point the program to new possible solutions How the current program works: I need help either figuring out a better way to solve this randomly, or even better, to have an algorithm that will allow the computer to systematically solve the puzzle. I've come to learn! Please help! Please help with: I eventually realized I have two options to get the computer to solve this:Ī) Allow the computer to solve by randomly selecting switchesī) Create an algorithm that will allow the computer to solve the puzzle more efficiently.īeing a new programmer (halfway through CodeAcademy tutorials, halfway through LPTHW, and currently working through the MIT edX computer science Python course), I feel I'm a little limited in my abilities to figure this out. I figured out how to get the mechanics of the puzzle working correctly. Here's a YouTube video of the puzzle within the game: She came across a puzzle I decided I'd try to program a solution for.Īctivating a switch either turns ON or OFF that switch, and toggles its adjacent switches as well. So, my wife was playing Hammerwatch on Steam.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |