Created
March 30, 2013 08:41
-
-
Save hiroshi-maybe/5275905 to your computer and use it in GitHub Desktop.
Split an integer to a set of integers (i.e. split_int 5 3 -> [1,1,3], [1,2,2])
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
| split_int :: Int -> Int -> [[Int]] | |
| split_int n set_num = split_int_helper n set_num 1 | |
| split_int_helper n 1 _ = [[n]] | |
| split_int_helper n set_num start_idx = do | |
| let last_idx = truncate $ (fromIntegral n)/(fromIntegral set_num) | |
| x <- [start_idx..last_idx] | |
| y <- split_int_helper (n-x) (set_num-1) x | |
| return (x:y) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment