winner(X):- format('Winner is ~s', X).
win(X1, X2, X3):- X1 == X2, X2 == X3, winner(X1).
winRow([X1, X2, X3|Tail]):- win(X1, X2, X3); winRow(Tail).
winCross([ 
    X1, _, X4,
    _, X2, _,
    X5, _, X3]):- win(X1, X2, X3); win(X4, X2, X5).

nextColumnItem([_, _, X|Tail], X, Tail).
winColumn([X1|Tail]):- 
    nextColumnItem(Tail, X2, Tail2),
    nextColumnItem(Tail2, X3, _),
    win(X1, X2, X3);
    winColumn(Tail).

win(X):- winRow(X); winCross(X); winColumn(X).

whoWins:- win([
  x, _, o,
  o, x, o,
  x, _, o
  ]).

/** <examples>

?- whoWins.
*/