Skip to content

Instantly share code, notes, and snippets.

@yasuabe
Created May 12, 2017 13:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yasuabe/a47021f50448e535dc3db08b1e7994ea to your computer and use it in GitHub Desktop.
Save yasuabe/a47021f50448e535dc3db08b1e7994ea to your computer and use it in GitHub Desktop.
haskell implementation of simpath: Main
import System.Environment
import Simpath.Border (borders)
import Simpath.Edge (Edge, edge, modify)
import Simpath.CounterMap
gridEdges :: Int -> [Edge]
gridEdges size = upper ++ lower
where
upper = snd $ foldl (\(c, ts) n -> (c + n, ts ++ edgesAt n c)) (0, []) [1 .. size-1]
where edgesAt n acc = map (+ acc) [1 .. n] >>= addPair
where addPair i = let f = edge i . (i + n +) in map f [0, 1]
lower = reverse $ map (modify (size^2 + 1 -)) upper
main :: IO ()
main = do args <- getArgs
print $ countPaths $ borders $ gridEdges $ (read $ head args :: Int)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment