`
gaofen100
  • 浏览: 1243642 次
文章分类
社区版块
存档分类
最新评论

熄灯问题 Lights Out Puzzle

 
阅读更多

From : http://mathworld.wolfram.com/LightsOutPuzzle.html

转化为高斯消元法,POJ 1222

---

Lights Out Puzzle

DOWNLOAD Mathematica Notebook

LightsOutSwitch

A one-person game played on a rectangular lattice of lamps which can be turned on and off. A move consists of flipping a "switch" inside one of the squares, thereby toggling the on/off state of this and all four vertically and horizontally adjacent squares. Starting from a randomly chosen light pattern, the aim is to turn all the lamps off. The problem of determining if it is possible to start from set of all lights being on to all lights being off is known as the "all-ones problem." As shown by Sutner (1989), this is always possible for a square lattice (Rangel-Mondragon).

This can be translated into the following algebraic problem.

1. Each lamp configuration can be viewed as a matrix L with entries in Z_2 (i.e., a binary matrix ), where each 1 represents a burning light and 0 represents a light turned off. For example, for the 3×3 case,

 L=[0 1 0; 1 1 0; 0 1 1]
(1)

2. The action of the switch placed at (i,j) can be interpreted as the matrix addition L+A_(ij) , where A_(ij) is the matrix in which the only entries equal to 1 are those placed at (i,j) and in the adjacent positions; there are essentially three different types of matrices A_(ij) , depending on whether (i,j) is a corner entry,

 A_(11)=[1 1 0; 1 0 0; 0 0 0]
(2)

a side entry,

 A_(12)=[1 1 1; 0 1 0; 0 0 0]
(3)

or a middle entry,

 A_(22)=[0 1 0; 1 1 1; 0 1 0]
(4)

3. Since matrix addition is commutative, it follows that the order in which the moves are performed is irrelevant.

4. Every winning combination of moves can be expressed mathematically in the form:

 L+sum_(i,j)x_(ij)A_(ij)=0.
(5)

Here, 0 denotes the zero matrix , which corresponds to the situation where all lights are turned off, and each coefficient x_(ij) represents the number of times that switch (i,j) has to be pressed. Because we are solving the equations (mod 2), they can therefore be written in the equivalent form

 sum_(i,j)x_(ij)A_(ij)=L.
(6)

Furthermore, it suffices to consider 0 and 1 as the only possible values for x_(ij) . Hence, the above equality is in fact a system of linear equations in the indeterminates x_(ij) over the field Z_2 .

LightsOut3By3

For example, the system corresponding to the initial (left) light pattern above can be written as

 [1 1 0 1 0 0 0 0 0; 1 1 1 0 1 0 0 0 0; 0 1 1 0 0 1 0 0 0; 1 0 0 1 1 0 1 0 0; 0 1 0 1 1 1 0 1 0; 0 0 1 0 1 1 0 0 1; 0 0 0 1 0 0 1 1 0; 0 0 0 0 1 0 1 1 1; 0 0 0 0 0 1 0 1 1][x_(11); x_(12); x_(13); x_(21); x_(22); x_(23); x_(31); x_(32); x_(33)]=[0; 1; 0; 1; 1; 0; 0; 1; 1].
(7)

It has exactly one solution: ((1,1,1) , (0,0,0) , (0,0,1) ), which means that the game is solved by pressing the switches (1,1) , (1,2) , (1,3) , and (3,3) (corresponding to the red dots in the figure above). Since the matrix of the above system of equations has maximal rank (it is a 9×9 matrix with nonzero determinant), the game on a 3×3 -lattice is always solvable.

LightsOut3By2Solvable

In general, the solvable patterns of the m×n lattice are those which are obtained from the no-light pattern by pushing some switches. In the language of linear algebra, they are the m×n -matrices which are sums of some matrices A_(ij) . For instance, the solvable patterns of the 3×2 -lattice are illustrated above. All other rectangles of size 4×3 or less are solvable for every possible starting pattern.

LightsOut3By2Solutions

Multiple solutions are sometimes possible. For example, going from lights all on to all off in the 3×2 case, there are four possible solutions to the all-lights pattern, illustrated above.

LightsOut3By2

Some patterns have no solutions. For example, in the 3×2 pattern shown above, it is impossible to turn off all the lights.

LightsOutSquareSolutions

As shown by Sutner (1989), going from all lights on to all lights off is always possible for any size square lattice. The above illustration shows all possible solutions for n=2 to 7. The numbers of solutions (ignoring rotation and reflection) for n=1 , 2, ... are 1, 1, 1, 16, 4, 1, 1, 1, 256, 1, 64, 1, 1, 16, 1, ... (Sloane's A075462 ), and the corresponding minimal numbers of buttons to be pressed are 1, 4, 5, 4, 15, 28, 33, 40, 25, 44, 55, 72, 105, 56, 117, ... (Sloane's A075464 ). The board sizes with unique solutions (counting boards having equivalent solutions by rotation or reflections as distinct) are therefore 1, 2, 3, 6, 7, 8, 10, 12, 13, 15, 18, 20, ... (Sloane's A076436 ; Cowen and Kennedy 2000).

LightsOutUniqueSquareSolutions

Removing solutions that are equivalent by rotation or reflection gives the distinct solutions illustrated above, of which there are 1, 1, 1, 5, 1, 1, 1, 1, 43, 1, 10, 1, 1, 5, 1, ... (Sloane's A075463 ). The board sizes with unique solutions (counting boards having equivalent solutions by rotation or reflections as equivalent) are therefore 1, 2, 3, 5, 6, 7, 8, 10, 12, 13, 15, 17, 18, ... (Sloane's A076437 ).

This entry contributed by Margherita Barile

REFERENCES:

Caro, Y. "Simple Proofs to Three Parity Theorems." Ars Combin. 42 , 175-180, 1996.

Conlon, M.M.; Falidas, M.; Forde, M.J.; Kennedy, J.W.; McIlwaine, S.; and Stern, J. "Inversion Numbers of Graphs." Graph Th. Notes New York 37 , 42-48, 1999.

Cowen, R. and Kennedy, J. "The Lights Out Puzzle." Math. Educ. Res. 9 , 28-32, 2000. http://library.wolfram.com/infocenter/Articles/1231/ .

Cowen, R.; Hechler, S.H.; Kennedy, J.W.; and Ryba, A. "Inversion and Neighborhood Inversion in Graphs." Graph Th. Notes New York 37 , 37-41, 1999.

Goldwasser, J. and Klostermeyer, W. "Maximization Versions of 'Lights Out' Games in Grids and Graphs." Congr. Numer. 126 , 99-111, 1997.

JavaScript Source. "Lights Out." http://javascript.internet.com/games/lights-out.html .

Millstone Website. "Lights Out." http://www.millstone.demon.co.uk/games/lightsout/start.htm .

Rangel-Mondragon, J. "A Catalog of Cellular Automata." http://library.wolfram.com/infocenter/MathSource/505/ .

Raguet-Schofield, R. "Lights Out Palette Demonstration." http://library.wolfram.com/infocenter/Demos/4817/ .

Sloane, N.J.A. Sequences A075462 , A075463 , A075464 , A076436 , and A076437 in "The On-Line Encyclopedia of Integer Sequences."

Sutner, K. "Linear Cellular Automata and the Garden-of-Eden." Math. Intelligencer 11 , 49-53, 1989.

Whitman College Department of Mathematics. "Lights Out." http://www.whitman.edu/offices_departments/mathematics/lights_out/ .




CITE THIS AS:

Barile, Margherita . "Lights Out Puzzle." From MathWorld --A Wolfram Web Resource, created by Eric W. Weisstein . http://mathworld.wolfram.com/LightsOutPuzzle.html

分享到:
评论

相关推荐

    The-Lights-Out-Puzzle:熄灯难题编码器求解器

    由以下人员共同准备的文件: · Daniel Olañeta Fariña· Ángel Álvarez Rey链接到GitHub项目: : 这种做法是在Java(版本11.0.9)中开发的。 执行说明: 要执行此实践,我们需要预先具有包含编码器条目的“ ex ...

    NPuzzle求解研究报告.docx

    NPuzzle 问题是一种经典的搜索问题,旨在找到从初始状态到目标状态的最短路径。在该论文研究报告中,我们将深入探讨 NPuzzle 问题的解决方法和算法。 NPuzzle 问题定义 NPuzzle 问题是一种搜索问题,其中给定一...

    n_puzzle_state

    在本文中,我们将深入探讨如何使用A*搜索算法来解决15-puzzle问题,这是一个典型的人工智能领域的问题。A*算法是一种启发式搜索方法,它结合了Dijkstra算法的最短路径查找与最佳优先搜索的特性,通过评估每个节点的...

    8 puzzle 问题 C# 代码

    8 Puzzle 问题是一种经典的组合优化问题,源自19世纪末的智力拼图游戏。它由一个3x3的网格组成,其中8个方块分别标有数字1到8,还有一个空格。玩家通过将空格与其他方块交换位置,尝试将初始布局调整为预设的目标...

    用Qt(C++)编写的15puzzle与8puzzle游戏.zip

    用Qt(C++)编写的15puzzle与8puzzle游戏.zip用Qt(C++)编写的15puzzle与8puzzle游戏.zip用Qt(C++)编写的15puzzle与8puzzle游戏.zip用Qt(C++)编写的15puzzle与8puzzle游戏.zip用Qt(C++)编写的15puzzle与8...

    一个“网页加载中”的特效代码 - 4ngel's blog - Powered by Sablog-X

    根据给定文件的信息,本文将详细解析一个网页加载中的特效代码。...接下来,我们将分几个部分来详细探讨这段代码的关键知识点。 ### 一、JavaScript部分 #### 1.1 动态更新加载进度 JavaScript部分是实现加载进度动画...

    8-Puzzle-Game_Python8puzzle_puzzle游戏_8puzzlePython_ai_8puzzlesol

    在这个Python程序中,我们使用了广度优先搜索(BFS)算法来解决8-Puzzle问题。 首先,我们需要了解8-Puzzle的状态表示。每个状态是一个9元素的数组,其中每个元素代表格子上的数字或0表示空格。例如,一个状态可能...

    Java PUZZLE Java 解惑

    Java PUZZLE Java 解惑 Java PUZZLE Java 解惑 Java PUZZLE Java 解惑Java PUZZLE Java 解惑 Java PUZZLE Java 解惑 Java PUZZLE Java 解惑

    论文研究-Rotate-N-Puzzle问题可解性分析及求解 .pdf

    Rotate-N-Puzzle问题与N-Puzzle问题类似,问题空间也具有组合爆炸性质。经证明,Rotate-N-Puzzle的任何一个初始布局都是可解的。在此结论的基础上,给出了解长度的上界。提出了一种分治算法,在算法中的每一步,采用...

    Puzzle Killer(完美解决八数码和十五数码问题)

    《Puzzle Killer:八数码与十五数码问题的高效求解》 在计算机科学领域,解决谜题类问题是一项挑战性的任务,尤其是八数码问题和十五数码问题。这两个经典的逻辑游戏,以其独特的规则和复杂的解题过程,吸引了众多...

    15 puzzle C语言IDA* 求解算法

    在15 Puzzle问题中,曼哈顿距离通常比汉明距离表现更好,因为它提供了一个更准确的估计,引导搜索过程更快地接近目标状态。 通过上述的C语言实现,我们可以有效地求解15 Puzzle问题。使用IDA*算法,我们可以减少...

    8puzzle & a* pathfinder

    理解并实现8 Puzzle和A*算法对于学习搜索算法和优化问题的解决方法具有重要意义。通过对这些代码的深入学习,我们可以掌握如何运用计算机科学理论来解决实际问题,同时也能提升编程技巧和问题解决能力。

    eight puzzle问题基于bfs算法分析及代码

    bfs在八数码问题上的应用 包含初始状态和目标状态 状态是否存在是我们首先要解决的问题 每一个状态的表示 左右前后移动的操作 找出0所在的文职 是否存在中间状态

    15谜(15-puzzle)问题的求解

    15谜问题,又称为15滑块游戏或15拼图,是一个经典的逻辑和智力挑战,玩家需要通过滑动15个数字方块到一个4x4的网格上,使得数字顺序从1到15排列,空白格通常位于右下角。这个谜题在信息技术和人工智能领域具有重要的...

    Flash crossword puzzle generater

    Flash based crossword puzzle generater, output format: XML

    Image Puzzle_C#8puzzlegame_picturepuzzle_

    8-puzzle,又称为滑块谜题,是一种经典的智力游戏,通常在一个3x3的网格上进行,玩家需要通过滑动方块来达到预设的目标布局。在这个4x4版本中,游戏难度有所降低,更适合初学者体验和学习。 1. **游戏设计原理**: ...

    the c puzzle book

    从给定的信息来看,标题和描述提及的是一本关于C语言的谜题书籍,即《C Puzzle Book》。虽然描述中的信息较为简短且含糊,但我们可以从书名推测,这本书可能包含了一系列与C语言相关的编程挑战或谜题,旨在帮助读者...

    Puzzle for 3dMax拼图随机生成器工具下载

    3DMAX拼图随机生成器(英文:Puzzle),是一款为3dsMax开发的拼图建模小工具,可以随机创建可编辑多边形3D拼图对象。可批量生成阵列。 安装方法:点击3dmax主菜单-脚本-运行脚本,选择Puzzle-1.0.0-zh_CN运行即可。

    block puzzle jewel 方块拼图消除游戏安卓源码

    8. **错误处理和调试**:源码中应包含错误处理代码,如异常捕获和日志记录,这有助于在开发过程中定位和修复问题。 9. **性能优化**:高效的游戏运行离不开性能优化,源码可能会包含一些优化技巧,如减少不必要的...

    java puzzle

    在Java编程世界里,"Java Puzzle"通常指的是那些巧妙或者具有挑战性的编程问题,它们能够测试和提升开发者对Java语言的理解。这些谜题通常涉及到语言特性、数据结构、算法以及面向对象编程等核心概念。本Java书籍的...

Global site tag (gtag.js) - Google Analytics