Skip to content

Instantly share code, notes, and snippets.

@recursivecurry
Created October 14, 2014 14:29
Show Gist options
  • Save recursivecurry/ef7797fb4a5bb7494500 to your computer and use it in GitHub Desktop.
Save recursivecurry/ef7797fb4a5bb7494500 to your computer and use it in GitHub Desktop.
-- subset generator
-- ./Test
-- 3
-- [[1,2,3],[2,3],[1,3],[3],[1,2],[2],[1],[]]
-- ./Test
-- 4
-- [[1,2,3,4],[2,3,4],[1,3,4],[3,4],[1,2,4],[2,4],[1,4],[4],[1,2,3],[2,3],[1,3],[3],[1,2],[2],[1],[]]
module Main where
subMain :: Int -> [Int] -> [[Int]]
subMain 0 elements = [elements]
subMain maxNum elements = (subMain (maxNum-1) (maxNum:elements)) ++ (subMain (maxNum-1) elements)
main :: IO ()
main =
do line <- getLine
let maxNum = read line :: Int
let subSets = subMain maxNum []
print subSets
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment