Skip to content

Instantly share code, notes, and snippets.

@yuga
Created February 28, 2013 05:52
Show Gist options
  • Save yuga/5054544 to your computer and use it in GitHub Desktop.
Save yuga/5054544 to your computer and use it in GitHub Desktop.
-- |
-- Create patterns to divide.
--
-- >>> divide 4
-- [[1,1,1,1],[1,1,2],[1,2,1],[1,3],[2,1,1],[2,2],[3,1],[4]]
--
divide :: Int -> [[Int]]
divide 0 = [[]]
divide n = [[x]:y | x <- [1..n], y <- divide (n-x)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment