1
0
Fork 0
mirror of https://gitlab.com/mfocko/CodeWars.git synced 2024-11-09 02:59:06 +01:00
CodeWars/6kyu/take_a_ten_minute_walk/solution.hs

11 lines
343 B
Haskell
Raw Normal View History

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"