考虑到Rebol 即将公开发布开源软件的时间已经很久很久了,我回到了我的宠物方言中来解决这个Bingo问题。我也许很快就可以将Rebmu分发为自己的Teensy GPL软件包。:)
在紧凑的表示法中:
rtZ5[GisGpcRaZisGaAPgPCaSB6zAPv'*]l5[AgL5[apGfAsk+A5]]hd+Gu[raGin-NTrM'*fisGv5]p"BINGO!"
该方言使用了一种我称之为糊涂的技巧,在Rebmu页面上有解释。从某种意义上讲它是“合法的”,因为它不会欺骗解析器。这是有效的Rebol ...并且实际上可以自由地与普通代码以及(长号)“长格式” Rebmu混合使用……BTW为141个字符:
[rt z 5 [g: is g pc r a z is g a ap g pc a sb 6 z ap v '*] l 5 [a: g l 5 [ap g f a sk+ a 5]] hd+ g u [ra g in- nt r m '* fis g v 5] p "BINGO!"]
(鉴于我认为压缩是一种无需自动化或编译就可以完成的技巧,实际上我以无格式形式开发代码。这并不困难。)
这实际上很简单,没什么特别的-我相信其他Rebol程序员可以省掉一些事情。一些 评论源在GitHub上,但是我使用的主要技巧是在很长的序列中构建所有可能的解决方案(“列表”,“数组”,“您拥有什么”)。我在输入循环中构建了对角线解,因为它在头部需要五个插入,在尾部需要五个追加才能完成……而且已经有一个五迭代循环。
整个过程很容易映射到Rebol代码,而且我还没有通过转置或其他经常出现的头将任何“矩阵库”扔到Rebmu中。有一天,我会这样做,但现在我只是在尝试相对接近Rebol本身的媒介。隐秘的事物,例如:
[g: is g pc r a z is g a ap g pc a sb 6 z ap v '*]
...非常简单:
[
; assign the series pointer "g" to the result of inserting
; the z'th element picked out of reading in some series
; from input that was stored in "a"...this pokes an element
; for the forward diagonal near the front of g
g: insert g (pick (readin-mu a) z)
; insert the read-in series "a" from above into "g" as well,
; but *after* the forward diagonal elements we've added...
insert g a
; for the reverse diagonal, subtract z from 6 and pick that
; (one-based) element out of the input that was stored in "a"
; so an element for the reverse diagonal is at the tail
append g (pick a (subtract 6 z))
; so long as we are counting to 5 anyway, go ahead and add an
; asterisk to a series we will use called "v" to search for
; a fulfilled solution later
append v '*
]
注意:为清楚起见,在上面添加了括号。但是Rebol程序员(例如讲英语的人)通常避免使用额外的结构性标注来表示交流中的语法...而是将其保存用于其他应用...
就像额外的花钱说明这实际上有多有趣一样,我将混合一些普通代码来加总电路板。编程样式实际上是...兼容的:
rtZ5[GisGpcRaZisGaAPgPCaSB6zAPv'*]
temp-series: g
sum: 0
loop 5 * 5 [
square: first temp-series
if integer! == type? square [
sum: sum + square
]
temp-series: next temp-series
]
print ["Hey grandma, the board sum is" sum]
l5[AgL5[apGfAsk+A5]]hd+Gu[raGin-NTrM'*fisGv5]p"BINGO!"
这也是有效的Rebmu,并且在和您玩Bingo之前,它会给您带来一笔不错的董事会收入。在给出的示例中,它说Hey grandma, the board sum is 912
。这可能是正确的。但是你明白了。:)
row
为一个字符的名称。未经测试:尝试i in'*'*5]
替换[x=='*']
为[x==i]
。