Skip to content

Instantly share code, notes, and snippets.

@soimort
Created April 15, 2013 13:05
Show Gist options
  • Save soimort/5387914 to your computer and use it in GitHub Desktop.
Save soimort/5387914 to your computer and use it in GitHub Desktop.
GCJ 2013 Qualification Round - Problem A
-- Authored by tanakh
{-# LANGUAGE TupleSections #-}
import Control.Applicative
import Control.Monad
import Data.List
import Text.Printf
main :: IO ()
main = do
n <- readLn
forM_ [1..n] $ \cn -> do
bd <- replicateM 4 getLine
_ <- getLine
let check c = any (all (\(i, j) -> is $ bd !! i !! j)) ps where
is d = d == c || d == 'T'
ps = [ [ (i, j) | j <- [0..3]] | i <- [0..3] ] ++
[ [ (j, i) | j <- [0..3]] | i <- [0..3] ] ++
[ map (\i -> (i, i)) [0..3] ] ++
[ map (\i -> (i, 3-i)) [0..3] ]
let ans = case () of
_ | check 'X' -> "X won"
| check 'O' -> "O won"
| any (any (== '.')) bd -> "Game has not completed"
| otherwise -> "Draw"
printf "Case #%d: %s\n" (cn :: Int) ans
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment