diff options
| author | Steve Rogerson <steve.git@yewtc.demon.co.uk> | 2020-10-23 12:27:13 +0100 |
|---|---|---|
| committer | Steve Rogerson <steve.git@yewtc.demon.co.uk> | 2020-10-23 12:27:13 +0100 |
| commit | 44c2bbf87ac613a2a442cc4e54d810c20a042ff2 (patch) | |
| tree | 3af39af1f773a9e6b44e91a3852a7553dae7c986 /challenge-083/jeongoon/haskell/Combinations.hs | |
| parent | ff3c07c3e4409c8d507b3e69496c690b58de524d (diff) | |
| parent | 89421f14095148aefcd254da3d728b6150b22cc3 (diff) | |
| download | perlweeklychallenge-club-44c2bbf87ac613a2a442cc4e54d810c20a042ff2.tar.gz perlweeklychallenge-club-44c2bbf87ac613a2a442cc4e54d810c20a042ff2.tar.bz2 perlweeklychallenge-club-44c2bbf87ac613a2a442cc4e54d810c20a042ff2.zip | |
Merge branch 'master' of https://github.com/manwar/perlweeklychallenge-club
Diffstat (limited to 'challenge-083/jeongoon/haskell/Combinations.hs')
| -rw-r--r-- | challenge-083/jeongoon/haskell/Combinations.hs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/challenge-083/jeongoon/haskell/Combinations.hs b/challenge-083/jeongoon/haskell/Combinations.hs new file mode 100644 index 0000000000..f8c5324f43 --- /dev/null +++ b/challenge-083/jeongoon/haskell/Combinations.hs @@ -0,0 +1,25 @@ +{- Copyright (c) 2020 JEON Myoungjin <jeongoon@g... > -} + +module Combinations + ( combinations + ) where + +combinations :: [a] -> Int -> [[a]] +combinations [] _ = [] +combinations (m:ms) 1 = [m] : (combinations ms 1) +combinations [_] 2 = [] +combinations [e,f] 2 = sequence [ [e],[f] ] +combinations (m:ms) 2 = sequence [ [m], ms ] ++ (combinations ms 2) +combinations mls n = + case totalLen `compare` n of + LT -> [] + EQ -> [mls] + _ -> [ let leaders = map (mls!!) ids + in leaders ++ followers | + ids <- combinations [ 0 .. room ] n', + let skipCount = (last ids) + 1, + followers <- (combinations (drop skipCount mls) 2) ] + where + totalLen = length mls + room = totalLen - 2 + n' = n - 2 |
