Created
January 12, 2016 12:58
-
-
Save jkramer/9c09f3603b46216e2cdc to your computer and use it in GitHub Desktop.
CodinGame - APU: Init Phase
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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