Created
January 11, 2016 14:04
-
-
Save jkramer/579f1d92a521057416da to your computer and use it in GitHub Desktop.
CodinGame - Thor
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 System.IO | |
main = do | |
hSetBuffering stdout NoBuffering -- DO NOT REMOVE | |
[lightx, lighty, initialtx, initialty] <- fmap (map read . words) getLine | |
mapM_ (\ x -> getLine >> putStrLn x) (path initialtx initialty lightx lighty) | |
path x y lx ly = | |
zipWith (++) (direction "S" "N" (y - ly)) (direction "E" "W" (x - lx)) | |
where | |
totalMoves = max (abs (x - lx)) (abs (y - ly)) | |
direction n p os | |
| os == 0 = replicate totalMoves "" | |
| os < 0 = replicate (abs os) n ++ replicate (totalMoves - abs os) "" | |
| os > 0 = replicate (abs os) p ++ replicate (totalMoves - abs os) "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment