Skip to main content
chars-=3
Source Link

Haskell, 172169

main=interact$(\x->last$"cat":[b|(a,b)<-[("ooo","lose"),("xxx","win")],any(==a)x]).(\x->x++(foldr(zipWith(:))(repeat[])x)++[zipWith++map(zipWith(!!)x a|a<-)[[0..],[2,1,0]]]0]]).take 3.lines

Input format: "X" is represented only by x, "O" only by o. Within each row, characters are simultaneous without spaces, etc. Rows are separated by new lines.

Generates all possible rows/columns/diagonals, then filters [("ooo","lose"),("xxx","win")] by their existence on the board, then selects the second word in the tuple, so we know which players won. We prepend "cat" so that we can take the last element of the list as our winner. If both players won, "win" will be last (list comprehensions maintain order). Since "cat" is always first, if a winner exists, it will be chosen, but otherwise a last element still exists as prepending "cat" guarantees nonemptyness.

EDIT: Shaved 3 characters by changing last list comprehension to map.

Haskell, 172

main=interact$(\x->last$"cat":[b|(a,b)<-[("ooo","lose"),("xxx","win")],any(==a)x]).(\x->x++(foldr(zipWith(:))(repeat[])x)++[zipWith(!!)x a|a<-[[0..],[2,1,0]]]).take 3.lines

Input format: "X" is represented only by x, "O" only by o. Within each row, characters are simultaneous without spaces, etc. Rows are separated by new lines.

Generates all possible rows/columns/diagonals, then filters [("ooo","lose"),("xxx","win")] by their existence on the board, then selects the second word in the tuple, so we know which players won. We prepend "cat" so that we can take the last element of the list as our winner. If both players won, "win" will be last (list comprehensions maintain order). Since "cat" is always first, if a winner exists, it will be chosen, but otherwise a last element still exists as prepending "cat" guarantees nonemptyness.

Haskell, 169

main=interact$(\x->last$"cat":[b|(a,b)<-[("ooo","lose"),("xxx","win")],any(==a)x]).(\x->x++(foldr(zipWith(:))(repeat[])x)++map(zipWith(!!)x)[[0..],[2,1,0]]).take 3.lines

Input format: "X" is represented only by x, "O" only by o. Within each row, characters are simultaneous without spaces, etc. Rows are separated by new lines.

Generates all possible rows/columns/diagonals, then filters [("ooo","lose"),("xxx","win")] by their existence on the board, then selects the second word in the tuple, so we know which players won. We prepend "cat" so that we can take the last element of the list as our winner. If both players won, "win" will be last (list comprehensions maintain order). Since "cat" is always first, if a winner exists, it will be chosen, but otherwise a last element still exists as prepending "cat" guarantees nonemptyness.

EDIT: Shaved 3 characters by changing last list comprehension to map.

element => word in the tuple
Source Link

Haskell, 172

main=interact$(\x->last$"cat":[b|(a,b)<-[("ooo","lose"),("xxx","win")],any(==a)x]).(\x->x++(foldr(zipWith(:))(repeat[])x)++[zipWith(!!)x a|a<-[[0..],[2,1,0]]]).take 3.lines

Input format: "X" is represented only by x, "O" only by o. Within each row, characters are simultaneous without spaces, etc. Rows are separated by new lines.

Generates all possible rows/columns/diagonals, then filters [("ooo","lose"),("xxx","win")] by their existence on the board, then selects the second elementword in the tuple, so we know which players won. We prepend "cat" so that we can take the last element of the list as our winner. If both players won, "win" will be last (list comprehensions maintain order). Since "cat" is always first, if a winner exists, it will be chosen, but otherwise a last element still exists as prepending "cat" guarantees nonemptyness.

Haskell, 172

main=interact$(\x->last$"cat":[b|(a,b)<-[("ooo","lose"),("xxx","win")],any(==a)x]).(\x->x++(foldr(zipWith(:))(repeat[])x)++[zipWith(!!)x a|a<-[[0..],[2,1,0]]]).take 3.lines

Input format: "X" is represented only by x, "O" only by o. Within each row, characters are simultaneous without spaces, etc. Rows are separated by new lines.

Generates all possible rows/columns/diagonals, then filters [("ooo","lose"),("xxx","win")] by their existence on the board, then selects the second element, so we know which players won. We prepend "cat" so that we can take the last element of the list as our winner. If both players won, "win" will be last (list comprehensions maintain order). Since "cat" is always first, if a winner exists, it will be chosen, but otherwise a last element still exists as prepending "cat" guarantees nonemptyness.

Haskell, 172

main=interact$(\x->last$"cat":[b|(a,b)<-[("ooo","lose"),("xxx","win")],any(==a)x]).(\x->x++(foldr(zipWith(:))(repeat[])x)++[zipWith(!!)x a|a<-[[0..],[2,1,0]]]).take 3.lines

Input format: "X" is represented only by x, "O" only by o. Within each row, characters are simultaneous without spaces, etc. Rows are separated by new lines.

Generates all possible rows/columns/diagonals, then filters [("ooo","lose"),("xxx","win")] by their existence on the board, then selects the second word in the tuple, so we know which players won. We prepend "cat" so that we can take the last element of the list as our winner. If both players won, "win" will be last (list comprehensions maintain order). Since "cat" is always first, if a winner exists, it will be chosen, but otherwise a last element still exists as prepending "cat" guarantees nonemptyness.

Source Link

Haskell, 172

main=interact$(\x->last$"cat":[b|(a,b)<-[("ooo","lose"),("xxx","win")],any(==a)x]).(\x->x++(foldr(zipWith(:))(repeat[])x)++[zipWith(!!)x a|a<-[[0..],[2,1,0]]]).take 3.lines

Input format: "X" is represented only by x, "O" only by o. Within each row, characters are simultaneous without spaces, etc. Rows are separated by new lines.

Generates all possible rows/columns/diagonals, then filters [("ooo","lose"),("xxx","win")] by their existence on the board, then selects the second element, so we know which players won. We prepend "cat" so that we can take the last element of the list as our winner. If both players won, "win" will be last (list comprehensions maintain order). Since "cat" is always first, if a winner exists, it will be chosen, but otherwise a last element still exists as prepending "cat" guarantees nonemptyness.