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]
하시겠습니까? 동점 인 경우 다른 일관된 값을 대신 출력 할 수 있습니까? 정확한 문자열을 인쇄하는 것은 실제로 골프의 일부가 아니므로 권장합니다. 향후 도전 과제 아이디어를 얻으려면 샌드 박스를 사용하는 것이 좋습니다 . :-)