9s3,ZU$$;ŒD$€Ẏf€⁸L€3e
s2ZÇƤ€ZFTḢ;Ḃ$
单调链接,获取动作列表并返回列表,[move, player]
其中玩家被标识为1
(第一个动作)和0
(第二个动作)。
在线尝试!
怎么样?
9s3,ZU$$;ŒD$€Ẏf€⁸L€3e - Link 1: any winning play?: list of player's moves:
9s3 - (range of) nine split into threes = [[1,2,3],[4,5,6],[7,8,9]]
$ - last two links as a monad:
$ - last two links as a monad:
Z - transpose = [[1,4,7],[2,5,8],[3,6,9]]
U - upend = [[7,4,1],[8,5,2],[9,6,3]]
, - pair = [[[1,2,3],[4,5,6],[7,8,9]],[[7,4,1],[8,5,2],[9,6,3]]]
$€ - last two links as a monad for €ach:
ŒD - diagonals = [[1,5,9],[2,6],[3],[7],[4,8]] or [[7,5,3],[4,2],[1],[9],[8,6]]
; - concatenate = [[1,2,3],[4,5,6],[7,8,9],[1,5,9],[2,6],[3],[7],[4,8]] or [[7,4,1],[8,5,2],[9,6,3],[7,5,3],[4,2],[1],[9],[8,6]]
Ẏ - tighten = [[1,2,3],[4,5,6],[7,8,9],[1,5,9],[2,6],[3],[7],[4,8],[7,4,1],[8,5,2],[9,6,3],[7,5,3],[4,2],[1],[9],[8,6]]
- i.e.: row1 row2 row3 diag\ x x x x col1 col2 col3 diag/ x x x x
- where x's are not long enough to matter for the rest...
⁸ - chain's left argument, list of player's moves
f€ - filter to keep those moves for €ach of those lists to the left
L€ - length of €ach result
3e - 3 exists in that? (i.e. were any length 3 when filtered down to only moves made?)
s2ZÇƤ€ZFTḢ;Ḃ$ - Main link: list of the moves e.g. [2,3,4,5,6,7,1,8,9]
s2 - split into twos [[2,3],[4,5],[6,7],[1,8],[9]]
Z - transpose [[2,4,6,1,9],[3,5,7,8]]
Ƥ€ - for Ƥrefixes of €ach:
Ç - call last link (1) as a monad [0,0,0,0,0] [0,0,1,1]
Z - transpose [[0,0],[0,0],[0,1],[0,1],[0]]
F - flatten [0,0,0,0,0,1,0,1,0]
T - truthy indices [ 6 8 ]
Ḣ - head (if empty yields 0) 6
$ - last two links as a monad:
Ḃ - modulo by 2 (evens are player 2) 0
; - concatenate [6,0]
[X, Y]
?如果出现平局,我们可以输出其他一致值吗?我建议这样做,因为打印这些确切的字符串实际上并不是打高尔夫球的一部分。对于未来的挑战想法,我建议使用沙盒。:-)