Need ideas on programming an algorithm to solve a particular puzzle.
Basically, the puzzle is:
There are 9 lights arranged in a 3×3 grid:
A B C
D E F
G H I
(lets say each letter represents a light)
If you turn on or off a light, the lights adjacent to it (up, down, left or right), but not diagonal, will turn on if they are are off, or turn off if they are on.
(e.g. if A is off, B is off, D is off and you turn on A, B and D will turn on as well)
If you are given a 3×3 grid with lights that are on or off arranged randomly, what would be the least number of lights you need to turn on or off, to turn off all the lights.
You can see this as a graph theory problem (http://en.wikipedia.org/wiki/Graph_theory).
Each given state of your puzzle is a Vertice of the graph, and each light switching is an edge that takes the Graph to another state.
Given a starting state, if you expand your graph breadth-first, your will find the sortest solution (http://en.wikipedia.org/wiki/Breadth-first_search).
It is beyond the scope of this answer to expand more than this. But I can point you to a python script I made to solve a similar but different 3×3 problem:
You can study my script to see what and why it does to solve this problem, and apply the same concepts to solve your problem on whatever language you desire.