Created
April 2, 2025 12:36
-
-
Save abuseofnotation/e0a31f9e92e0090bb71c9be472e61d9e to your computer and use it in GitHub Desktop.
another Haskell task
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
-- Return a list of all combinations (i.e. order doesn't matter) of the given length. | |
-- Example: Given "abc" and 2 the answer is ["ab","ac","bc"] but order doesn't matter at either level. | |
combinations :: [a] -> Int -> [[a]] | |
combinations letters 0 = [[]] | |
combinations [] p = [] | |
combinations (letter : letters) n = combinations letters n ++ map (letter :) (combinations letters (n -1)) | |
main = print $ combinations "abc" 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment