Skip to content

Instantly share code, notes, and snippets.

@J0J0
Last active August 29, 2015 14:02
Show Gist options
  • Save J0J0/37cb360c775b35246857 to your computer and use it in GitHub Desktop.
Save J0J0/37cb360c775b35246857 to your computer and use it in GitHub Desktop.
import System.Environment (getArgs)
data Dir = U | R deriving(Show)
type Link = [Dir]
shuf :: Link -> Int -> Int -> [Link]
shuf ds 0 0 = [ds]
shuf ds 0 q = shuf (R:ds) 0 (q-1)
shuf ds p 0 = shuf (U:ds) (p-1) 0
shuf ds p q =
up ++ right
where
up = shuf (U:ds) (p-1) q
right = shuf (R:ds) p (q-1)
print_permute ylen xlen = do
sequence_ $ map print $ shuf [] ylen xlen
main = do
args <- getArgs
case args of
[xlen,ylen] -> print_permute (read ylen) (read xlen)
_ -> putStrLn "need exactly two arguments"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment