X-Git-Url: https://git.njae.me.uk/?a=blobdiff_plain;f=src%2Ftask1%2Ftask1.hs;h=b0e263031853ee045dcf3f6cdab8feceed1d4e8a;hb=71da18e8360633ccc00b74ef62fd1fe60a3b9cda;hp=071fe68f3d1310f88b1f35e42c83cbee92e9ae41;hpb=c3a235494fa4e2aca91cadf94b3c5890baa7734e;p=summerofcode2018soln.git diff --git a/src/task1/task1.hs b/src/task1/task1.hs index 071fe68..b0e2630 100644 --- a/src/task1/task1.hs +++ b/src/task1/task1.hs @@ -2,13 +2,15 @@ import Data.List (foldl') -- import the strict fold -- number of steps type Distance = Int + +-- easting, northing type Position = (Int, Int) -- the directions. See below for functions for turning data Direction = North | East | South | West deriving (Enum, Show, Bounded, Eq) --- direction, easting, northing +-- the currenct state of a Mowmaster data Mowmaster = Mowmaster { direction :: Direction , position :: Position } deriving (Show, Eq) @@ -55,7 +57,7 @@ readInstruction i = readInstruction' (head i) (tail i) readInstruction' _ t = Comment t -initialMowmaster = Mowmaster North (0, 0) +initialMowmaster = Mowmaster East (0, 0) -- Calculate manhattan distance from start to this state @@ -73,7 +75,7 @@ execute m (Comment _) = m -- Move in the current direction -forward :: Int -> Direction -> Position -> Position +forward :: Distance -> Direction -> Position -> Position forward s North (e, n) = (e, n+s) forward s South (e, n) = (e, n-s) forward s West (e, n) = (e-s, n)