给定一个简单平台游戏的级别,您的任务是制作一个程序或函数,以确定某个级别是否可以获胜。平台游戏级别是4个字符高和任意数量的字符宽。在一个水平上,每个水平空间都有一个平台:
======= =
== = =
=== =====
= ==== === 这个游戏由跳跃组成。跳转从跳台上方的空间开始,最后是跳转到平台上方的空间(这些空间可以在4个平台的高度水平之上)。要完成跳转,必须可以在四个或更短的时间内(包括起点/终点)向上、向下、左侧和右侧移动,这些移动不能通过平台。下面是一些示例(标记为A表示启动平台,B标记为结束平台):
>>>
^ B
=A
= >>>>
=A B=>>
^B
A沿平台的水平移动仅仅是向一个方向移动的跳跃:
>>
==AB===这名球员将从最左边的平台开始,站在最右边的平台上获胜(标记为vs):
v === v
=== ==可赢的:
=== ==
= =====
= ==
= ==
=== ==== ==== =
===
=
=== == == =
=
= == == =不可赢的:
======
====== ======= =
= =
=
= =
=
= =
== == ==== 如果一个级别是可winnable的,则程序应该输出一个不同的值,如果不是,则输出一个不同的值。它可以以任何合理的形式接受输入,例如具有任意两个不同字符、矩阵或2d数组的ASCII艺术。
代码高尔夫,所以最短的答案每种语言获胜。
发布于 2019-12-03 23:45:29
Õcð í
o
v
à cá ®pV uWÃd_äÈcY ó x_raÃ<4 Ãr*临时修复通过使用排列允许向后跳转(实际上是低效的),不久将尝试@Nick解决方案。
z cð í // get each column height and pair with column index
o // save end position and remove from array
v // same for start pos
à cá // combinations of permutations
®pV uWÃ // restore end and start
d // return true if any returns true to..
_ ... Ãr* // reduce result
ä // pass each consecutive x,y
ÈcY ó // 'reshape~transpose' => [ platform pair, index pair]
x_raà // sum of absolute difference of each pair
<4 // return if less for each pair因“无知的化身”而得救2
-Q,76 字节数Õcð í ïÈcY ó x_raÃ<4î*JÃòUÎl
g0_ma
@T=Uc x UgUy_x_>0}Ãð _maÃT¥Uc x}a
o x >0“尼克·肯尼迪”( 果冻回答 )的翻译效率要高得多,但更长,我认为可以缩短。
ŒṪ => Õcð í M ultidimensional truthy indices of each
ạþ` => ïÈcY òUÎl O uter table using absolute difference and with the same argument on both sides:
§ => ó x_ra Sum innermost lists
<4 => Ã<4Ã Less than 4
N => ®*JÃ Negate
A1¦ => g0_ma Absolute top row
ÐL => @T=Uc x...T¥Uc x}a Apply the following until no changes:
On my side I used T to store the total of the whole matrix to check if it changed because g() modify the original matrix.
A $¦ => Ug..._maà Absolute the rows indicated by the following:
»/ => Uy_x_>0} Max of each column :
on my side I rotated the table and reduced to get the positive rows
T => Ãð Truthy indices (i.e. where there’s a 1 in the column)
Ṫ => o Finally take the last row
Ṁ => x >0 Max : on my side >0https://codegolf.stackexchange.com/questions/196593
复制相似问题