Lights Out - Find the solution
Ruby (130) (121) (113) (102)

EDIT: Saved 9 characters, thanks to Howard.

EDIT 2: Another 8 characters, courtesy of Howard.

EDIT 3: Saved 11 more characters after learning how to use Ruby's % operator for sprintf.

b=(0..4).map{gets.to_i 2}
32.times{|x|z=0;k=b.map{|i|x=z^i^31&amp;(x&lt;&lt;1^x&gt;&gt;1)^z=x;'%05b'%z}
puts k if x&lt;1}


Accepts 5 lines of input from stdin. Outputs all solutions as 5x5 grids as specified, though there are no extra line breaks between solutions (or between the input and the solutions).

Solutions are found by iterating through all 32 possibilities for the top row, since the top row determines the switches that must be flipped in the following rows.

Input:

00000
00000
00110
01000
00101


Output:

00000
00000
00000
00110
00001
01110
10101
11011
10011
01111
10101
10101
00000
10011
10100
11011
00000
11011
00110
11010