高尔夫代码:熄灭

编程入门 行业动态 更新时间:2024-10-09 22:16:56
本文介绍了高尔夫代码:熄灭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

按字符数计算的最短代码,可解决输入灯熄灭的问题.

The shortest code by character count to solve the input lights out board.

熄灯板是一个大小可变的二维正方形网格,由两个字符组成-.表示关闭的灯光,*表示打开的灯光.

The lights out board is a 2d square grid of varying size composed of two characters - . for a light that is off and * for a light that is on.

要解决此问题,必须关闭所有灯".切换一个灯(即打开时关闭,关闭时打开)一次使5盏灯-所选的灯和周围的灯呈+(加号)形状. 选择"中间的灯将解决木板:

To solve the board, all "lights" have to be turned off. Toggling a light (i.e. turning off when it is on, turning on when it is off) is made 5 lights at a time - the light selected and the lights surround it in a + (plus) shape. "Selecting" the middle light will solve the board:

.*. *** .*.

自从熄灭以来!解决方案的顺序无关紧要,输出将是一块新的电路板,上面有要选择的灯泡的标记.上面的板的解决方案是

Since Lights Out! solution order does not matter, the output will be a new board with markings on what bulbs to select. The above board's solution is

... .X. ...

在没有侧面灯泡要关掉的角落关掉灯不会溢出:

Turning off a light in a corner where there are no side bulbs to turn off will not overflow:

... ..* .**

在这种情况下,选择右下角的灯泡只会关闭3个灯泡.

Selecting the lower-right bulb will only turn off 3 bulbs in this case.

Input: **.** *.*.* .***. *.*.* **.** Output: X...X ..... ..X.. ..... X...X

Input: .*.*. **.** .*.*. *.*.* *.*.* Output: ..... .X.X. ..... ..... X.X.X

Input: *...* **.** ..*.. *.*.. *.**. Output: X.X.X ..X.. ..... ..... X.X..

代码计数包括输入/​​输出(即完整程序).

Code count includes input/output (i.e full program).

推荐答案

Perl,172个字符

Perl, 333 251 203 197 190 172个字符.在此版本中,我们随机按下按钮,直到所有指示灯熄灭为止.

Perl, 172 characters

Perl, 333 251 203 197 190 172 characters. In this version, we randomly push buttons until all of the lights are out.

map{$N++;$E+=/\*/*1<<$t++for/./g}<>; $C^=$b=1<<($%=rand$t), $E^=$b|$b>>$N|($%<$t-$N)*$b<<$N|($%%$N&&$b/2)|(++$%%$N&&$b*2)while$E; die map{('.',X)[1&$C>>$_-1],$_%$N?"":$/}1..$t

更多推荐

高尔夫代码:熄灭

本文发布于:2023-11-29 09:34:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1646020.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:高尔夫   代码

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!