Last active
December 13, 2015 23:49
-
-
Save jhickner/4994022 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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