module Main ( main ) where main :: IO () main = pure () {- Input: Prelude>pp(ticktack (8,8) [(1,1),(8,8),(2,2),(3,3),(4,2),(3,2)]) ( width, height x o x o x o ) Expected output: ---------- | o| | | | | | | | | | o | | xox | |x | ---------- My output: My output: x xox o Position (8,8) doesn't show on play field. Tic tacs are showed upside down. -} type Pic = [String] pp :: Pic -> IO () pp x = putStr (concat (map (++"\n") x)) ticktack :: (Int, Int) -> [(Int, Int)] -> Pic ticktack _[] = [""] ticktack (x, y) tulp = if (x <= 0 || y <= 0) then [""] else split (x, y) (board (mark (x, y) (fill (x, y) tulp))) where split :: (Int, Int) -> String -> [String] split (lenx, leny) str = [ [ str!! (j * lenx + i) | i <- [0..(lenx - 1)] ] | j <- [0..(leny - 1)] ] board :: [Int] -> String board [] = "" board (x:xs) | x == 0 = " " ++ board xs | x == 1 = "x" ++ board xs | otherwise = "o" ++ board xs mark :: (Int, Int) -> [Int] -> [Int] mark (posx, posy) a = [ if ((order a x) < 0) then 0 else (if (mod (order a x) 2 == 0) then 1 else 2) | x <- [0..(posx * posy - 1)] ] where order :: [Int] -> Int -> Int order [] _ = - 10 -- -10 is a walkout, remains undefined positions for tic/tac blank, is limited to 10-1 pairs inside of tulpa order (x:xs) a = if (x == a) then 0 else 1 + order xs a fill :: (Int, Int) -> [(Int, Int)] -> [Int] fill _ [] = [] fill (posx, posy) (x:xs) = ((posx * snd x) + fst x) : fill (posx, posy) xs