Skip to content

@jhickner /drunkenWalk.hs
Last active

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
import Data.List
data Dir = N | S | E | W deriving (Eq, Show)
type Coord = (Int, Int)
(|+|) (x,y) (x',y') = (x+x',y+y')
infixl 6 |+|
toDelta d = case d of
N -> (0, -1)
S -> (0, 1)
E -> (1, 0)
W -> (-1, 0)
toPath = reverse . foldl' (\p c -> head p |+| c : p) [(0,0)]
halts = isDistinct . toPath . map toDelta
where isDistinct xs = xs == nub xs
walk = [N, N, E, E, S, S, W, W]
walk2 = [N, N, N, N, N, N, N, N, N, N]
{-
> halts walk
False
> halts walk2
True
-}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.