Skip to content

Instantly share code, notes, and snippets.

@jkramer
Created January 11, 2016 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkramer/579f1d92a521057416da to your computer and use it in GitHub Desktop.
Save jkramer/579f1d92a521057416da to your computer and use it in GitHub Desktop.
CodinGame - Thor
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