1
0
Fork 0
mirror of https://gitlab.com/mfocko/CodeWars.git synced 2024-11-08 18:49:07 +01:00
CodeWars/6kyu/take_a_ten_minute_walk/solution.hs
Matej Focko fc899b0b02
chore: initial commit
Signed-off-by: Matej Focko <mfocko@redhat.com>
2021-12-28 16:19:58 +01:00

10 lines
343 B
Haskell

module Codewars.Kata.TenMinuteWalk where
isValidWalk :: [Char] -> Bool
isValidWalk walk = (length . take 11) walk == 10 && (0, 0) == foldl change (0, 0) walk
where change (x, y) d = case d of
'n' -> (x, y + 1)
's' -> (x, y - 1)
'e' -> (x + 1, y)
'w' -> (x - 1, y)
_ -> error "invalid move"