Created
May 12, 2017 13:02
-
-
Save yasuabe/a47021f50448e535dc3db08b1e7994ea to your computer and use it in GitHub Desktop.
haskell implementation of simpath: Main
This file contains hidden or 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 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