Skip to content

Instantly share code, notes, and snippets.

@jkramer jkramer/thor.hs
Created Jan 11, 2016

Embed
What would you like to do?
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
You can’t perform that action at this time.