projects
/
summerofcode2018soln.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Tweaked comments
[summerofcode2018soln.git]
/
src
/
task1
/
task1.hs
diff --git
a/src/task1/task1.hs
b/src/task1/task1.hs
index 200d538afd1fb1af0a401e81876003baf38fd865..e7a4f4bacf3770fe7192a9296eaa84dafa58b2a1 100644
(file)
--- a/
src/task1/task1.hs
+++ b/
src/task1/task1.hs
@@
-1,18
+1,22
@@
import Data.List (foldl') -- import the strict fold
-- number of steps
import Data.List (foldl') -- import the strict fold
-- number of steps
-type Step = Int
+type Distance = Int
+
+-- easting, northing
type Position = (Int, Int)
type Position = (Int, Int)
+-- the directions. See below for functions for turning
data Direction = North | East | South | West
deriving (Enum, Show, Bounded, Eq)
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)
data Mowmaster = Mowmaster { direction :: Direction
, position :: Position
} deriving (Show, Eq)
-data Instruction = Forward Step
+-- one instruction for the mowmaster
+data Instruction = Forward Distance
| Clockwise
| Anticlockwise
| Comment String
| Clockwise
| Anticlockwise
| Comment String
@@
-35,7
+39,6
@@
part2 instruction_text = finalDistance $ executeAll instructions
executeAll = foldl' execute initialMowmaster
executeAll = foldl' execute initialMowmaster
-
-- Is this line a comment?
isComment :: String -> Bool
isComment ('#':_) = True
-- Is this line a comment?
isComment :: String -> Bool
isComment ('#':_) = True
@@
-70,6
+73,7
@@
execute m Clockwise = m {direction = turnCW (direction m)}
execute m Anticlockwise = m {direction = turnACW (direction m)}
execute m (Comment _) = m
execute m Anticlockwise = m {direction = turnACW (direction m)}
execute m (Comment _) = m
+
-- Move in the current direction
forward :: Int -> Direction -> Position -> Position
forward s North (e, n) = (e, n+s)
-- Move in the current direction
forward :: Int -> Direction -> Position -> Position
forward s North (e, n) = (e, n+s)
@@
-77,7
+81,6
@@
forward s South (e, n) = (e, n-s)
forward s West (e, n) = (e-s, n)
forward s East (e, n) = (e+s, n)
forward s West (e, n) = (e-s, n)
forward s East (e, n) = (e+s, n)
-
-- | a `succ` that wraps
turnCW :: (Bounded a, Enum a, Eq a) => a -> a
turnCW dir | dir == maxBound = minBound
-- | a `succ` that wraps
turnCW :: (Bounded a, Enum a, Eq a) => a -> a
turnCW dir | dir == maxBound = minBound