projects
/
summerofcode2018soln.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Task 6 done
[summerofcode2018soln.git]
/
src
/
task1
/
task1-mpc.hs
diff --git
a/src/task1/task1-mpc.hs
b/src/task1/task1-mpc.hs
index e2127b6d20467cf5feab7f163267284209f89b52..27b279a1718dba287650b8f56cd979fd56b04c02 100644
(file)
--- a/
src/task1/task1-mpc.hs
+++ b/
src/task1/task1-mpc.hs
@@
-33,7
+33,6
@@
data Mowmaster = Mowmaster { direction :: Direction
data Instruction = Forward Distance
| Clockwise
| Anticlockwise
data Instruction = Forward Distance
| Clockwise
| Anticlockwise
- | Comment String
deriving (Show, Eq)
deriving (Show, Eq)
@@
-48,10
+47,10
@@
part1 :: [Instruction] -> Int
part1 = length
part2 :: [Instruction] -> Int
part1 = length
part2 :: [Instruction] -> Int
-part2
instructions = finalDistance $ executeAll instructions
+part2
= finalDistance . executeAll
where executeAll = foldl' execute initialMowmaster
where executeAll = foldl' execute initialMowmaster
-initialMowmaster = Mowmaster
North
(0, 0)
+initialMowmaster = Mowmaster
East
(0, 0)
-- Calculate manhattan distance from start to this state
-- Calculate manhattan distance from start to this state
@@
-65,10
+64,9
@@
execute :: Mowmaster -> Instruction -> Mowmaster
execute m (Forward s) = m {position = forward s (direction m) (position m)}
execute m Clockwise = m {direction = turnCW (direction m)}
execute m Anticlockwise = m {direction = turnACW (direction m)}
execute m (Forward s) = m {position = forward s (direction m) (position m)}
execute m Clockwise = m {direction = turnCW (direction m)}
execute m Anticlockwise = m {direction = turnACW (direction m)}
-execute m _ = m
-- Move in the current direction
-- 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)
forward s North (e, n) = (e, n+s)
forward s South (e, n) = (e, n-s)
forward s West (e, n) = (e-s, n)