9s3,ZU$$;ŒD$€Ẏf€⁸L€3e
s2ZÇƤ€ZFTḢ;Ḃ$
動きのリストを取得してリストを返すモナドリンク。[move, player]
プレーヤーは1
(最初に行動する)および0
(行動するために2番目)として識別されます。
オンラインでお試しください!
どうやって?
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]
。同点の場合、代わりに他の一貫した値を出力できますか?これらの正確な文字列を印刷することは実際にはゴルフの一部ではないので、私はお勧めします。今後のチャレンジのアイデアのために、サンドボックスの使用をお勧めします。:-)