Function Repository Resource:

LightsOutSolution

Source Notebook

Get the solutions of the Lights Out game

Contributed by: Aster Ctor

ResourceFunction["LightsOutSolution"][rank]

gives the essential solution to the standard Lights Out game of the given rank.

Details and Options

A standard game starts with all lights on. Every time the player clicks a switch, the clicked light and its neighbors switch state.
A solution of Lights Out means a way to turn off all the lights; 1 indicates a click, while 0 indicates no click.
The Method option can take the following values:
"Unique"give a single solution
"All"give all solutions
"AllCount"count all solutions
"Essential"give all essential solutions
"EssentialCount"count all essential solutions

Examples

Basic Examples (2) 

Get a solution of the rank-5 Lights Out game:

In[1]:=
unique5 = ResourceFunction["LightsOutSolution"][5]
Out[1]=

Visualize this solution:

In[2]:=
plot = ArrayPlot[#, Mesh -> All, Frame -> False] & ;
plot@unique5
Out[3]=

Options (5) 

Method (5) 

Give a solution:

In[4]:=
ResourceFunction["LightsOutSolution"][4, Method -> "Unique"]
Out[4]=

Give all the solutions:

In[5]:=
ResourceFunction["LightsOutSolution"][4, Method -> "All"]
Out[5]=

Count all solutions:

In[6]:=
ResourceFunction["LightsOutSolution"][4, Method -> "AllCount"]
Out[6]=

An essential solution means there is no other rotation-reflection inequivalent solutions:

In[7]:=
ResourceFunction["LightsOutSolution"][4, Method -> "Essential"]
Out[7]=

Count essential solutions:

In[8]:=
ResourceFunction["LightsOutSolution"][4, Method -> "EssentialCount"]
Out[8]=

Neat Examples (1) 

Complex and beautiful patterns arise when the order is high:

In[9]:=
plot@ResourceFunction["LightsOutSolution"][35]
Out[9]=

Publisher

Aster Ctor (MoeNet)

Version History

  • 1.0.0 – 05 December 2019

Related Resources

License Information