Skip to content

Instantly share code, notes, and snippets.

@jkramer
Created January 12, 2016 12:58
Show Gist options
  • Save jkramer/9c09f3603b46216e2cdc to your computer and use it in GitHub Desktop.
Save jkramer/9c09f3603b46216e2cdc to your computer and use it in GitHub Desktop.
CodinGame - APU: Init Phase
import Control.Monad
import Data.List
main = do
[ _, height ] <- replicateM 2 (fmap read getLine)
cells <- fmap concat (forM [0 .. height - 1] (\ y -> fmap (parseRow y) getLine))
forM cells (putStrLn . findNext cells)
where
parseRow y cells = map ((,) y . fst) $ filter ((==) '0' . snd) $ zip [0..] cells
findNext cells cell@(y, x) =
unwords (map showCell [cell, fallback right, fallback below])
where
right = filter (\ (y', x') -> y == y' && x' > x) cells
below = filter (\ (y', x') -> x == x' && y' > y) cells
fallback [] = (-1, -1)
fallback (cell : _) = cell
showCell (y, x) = show x ++ " " ++ show y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment