果冻, 24 22 19 18 字节
-2因为不再需要处理
从连接join j@
到连接的空列表-1 ;
(对于所使用的方法,不需要在中间遇到错过的项,因为在三重奏的开头就可以了)
-2从切换P¬aSH
为oSH
(自从我们展平以来,可以得到两个结果,无论如何1
都将0.5
其中的一半过滤掉,并且具有多个相等的结果也不会影响所采用的方法)
-1感谢Xcoder先生(0索引)允许输入)
d3ZIỊoSH;µƝFf9Ḷ¤Q⁼
单链链接,其中包含一个整数列表,如果合法则[0,8]
返回真值(1
),否则返回假值()0
。
在线尝试!或见一个测试套件。
怎么样?
查看输入列表中每对相邻的0索引节点。如果整数除以两个中的三个相差2,则它们在顶部和底部行中;如果两个整数中的三个相除的模数相差2,则它们在左侧和右侧列中。此类对的总和除以2可以是三节点行的0索引中间节点或非整数值-因此,这些值首先插入0索引对的前面,然后再插入假节点(例如0.5
或3.5
)被删除,列表的结果列表被展平,然后去重复(以生成保留订单的唯一条目),最后与输入内容进行比较-对于合法的刷卡操作,所有这些最终都将成为禁止操作,而非法那些将添加丢失的中间节点和/或删除重复的节点(请注意,长度为1的输入列表不需要特殊的大小写,因为它没有相邻的对):
d3ZIỊoSH;µƝFf9Ḷ¤Q⁼ - left input is a list of integers e.g. [3,4,7,1,2,8,3]
µƝ - perform the chain to the left for adjacent pairs:
- e.g. for [a,b] in: [3,4] [4,7] [7,1] [1,2] [2,8] [8,3]
d3 - divmod by 3 [[1,0],[1,1]] [[1,1],[2,1]] [[2,1],[0,1]] [[0,1],[0,2]] [[0,2],[2,2]] [[2,2],[1,0]]
Z - transpose [[1,1],[0,1]] [[1,2],[1,1]] [[2,0],[1,1]] [[0,0],[1,2]] [[0,2],[2,2]] [[2,1],[2,0]]
I - differences [0,1] [1,0] [-2,0] [0,1] [2,0] [-1,-2]
Ị - abs(v)<=1 [1,1] [1,1] [0,1] [1,1] [0,1] [1,0]
S - sum (of [a,b]) 7 11 8 3 10 11
o - OR (vectorises) [1,1] [1,1] [8,1] [1,1] [10,1] [1,11]
H - halve (vectorises) [0.5,0.5] [0.5,0.5] [4,0.5] [0.5,0.5] [5,0.5] [0.5,5.5]
; - concatenate [0.5,0.5,3,4] [0.5,0.5,4,7] [4,0.5,7,1] [0.5,0.5,1,2] [5,0.5,2,8] [0.5,5.5,8,3]
F - flatten [0.5,0.5,3,4, 0.5,0.5,4,7, 4,0.5,7,1, 0.5,0.5,1,2, 5,0.5,2,8, 0.5,5.5,8,3]
¤ - nilad followed by link(s) as a nilad:
9 - literal nine
Ḷ - lowered range = [0,1,2,3,4,5,6,7,8]
f - filter keep [ 3,4, 4,7, 4, 7,1, 1,2, 5, 2,8, ,8,3]
Q - deduplicate [3,4,7,1,2,5,8]
⁼ - equal to the input? e.g. 0 (here because 5 was introduced AND because 3 was removed from the right)
以前的方法
果冻, 36 35 字节
9s3;Z$;“Æ7a‘DZ¤;U$;©0m€2iị®oµƝFQ⁼ȧȦ
在线尝试!或见一个测试套件。
怎么样?
与上述类似,但是构造了所有三节点行的可能性并执行查找(而不是使用divmod进行检查以将中间节点的总和减半)。
首先,构建三节点线列表:
9s3;Z$;“Æ7a‘DZ¤;U$;©0
9s3 - nine (implicit range) split into threes = [[1,2,3],[4,5,6],[7,8,9]]
$ - last two links as a monad:
Z - transpose = [[1,4,7],[2,5,8],[6,7,9]]
; - concatenate = [[1,2,3],[4,5,6],[7,8,9],[1,4,7],[2,5,8],[3,6,9]]
¤ - nilad followed by link(s) as a nilad:
“Æ7a‘ - code-page index list = [13,55,97]
D - decimal (vectorises) = [[1,3],[5,5],[9,7]]
Z - transpose = [[1,5,9],[3,5,7]]
; - concatenate = [[1,2,3],[4,5,6],[7,8,9],[1,4,7],[2,5,8],[3,6,9],[1,5,9],[3,5,7]]
$ - last two links as a monad:
U - upend = [[3,2,1],[6,5,4],[9,8,7],[7,4,1],[8,5,2],[9,6,3],[9,5,1],[7,5,3]]
; - concatenate = [[1,2,3],[4,5,6],[7,8,9],[1,4,7],[2,5,8],[3,6,9],[1,5,9],[3,5,7],[3,2,1],[6,5,4],[9,8,7],[7,4,1],[8,5,2],[9,6,3],[9,5,1],[7,5,3]]
0 - literal zero (to cater for non-matches in the main link since ị, index into, is 1-based and modular the 0th index is the rightmost)
; - concatenate = [[1,2,3],[4,5,6],[7,8,9],[1,4,7],[2,5,8],[3,6,9],[1,5,9],[3,5,7],[3,2,1],[6,5,4],[9,8,7],[7,4,1],[8,5,2],[9,6,3],[9,5,1],[7,5,3],0]
© - copy the result to the register
现在的决策:
...m€2iị®oµƝFQ⁼ȧȦ - left input is a list of integers e.g. [4,5,8,2,3,9,4]
µƝ - perform the chain to the left for adjacent pairs:
- i.e. for [a,b] in [[4,5],[5,8],[8,2],[2,3],[3,9],[9,4]]
... - perform the code described above = [[1,2,3],[4,5,6],[7,8,9],[1,4,7],[2,5,8],[3,6,9],[1,5,9],[3,5,7],[3,2,1],[6,5,4],[9,8,7],[7,4,1],[8,5,2],[9,6,3],[9,5,1],[7,5,3],0]
m€2 - modulo-2 slice €ach = [[1,3],[4,6],[3,9],[1,7],[2,8],[6,9],[1,9],[3,7],[3,1],[6,4],[9,7],[7,1],[8,2],[9,3],[9,1],[7,3],[0]]
i - index of [a,b] in that (or 0 if not there) e.g. [0,0,13,0,6,0]
® - recall from register = [[1,2,3],[4,5,6],[7,8,9],[1,4,7],[2,5,8],[3,6,9],[1,5,9],[3,5,7],[3,2,1],[6,5,4],[9,8,7],[7,4,1],[8,5,2],[9,6,3],[9,5,1],[7,5,3],0]
ị - index into (1-based & modular) e.g. [0,0,[8,5,2],0,[3,6,9],0]
o - OR [a,b] e.g. [[4,5],[5,8],[8,5,2],[2,3],[3,6,9],[9,4]]
F - flatten e.g. [4,5,5,8,8,5,2,2,3,3,6,9,9,4]
Q - deduplicate e.g. [4,5,8,2,3,6,9]
⁼ - equal to the input? e.g. 0 (here because 6 was introduced AND because 4 was removed from the right)
Ȧ - any and all? (0 if input is empty [or contains a falsey value when flattened - no such input], 1 otherwise)
ȧ - AND (to force an empty input to evaluate as 1 AND 0 = 0)