Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
4
Task/Combinations/Haskell/combinations-1.hs
Normal file
4
Task/Combinations/Haskell/combinations-1.hs
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
comb :: Int -> [a] -> [[a]]
|
||||
comb 0 _ = [[]]
|
||||
comb _ [] = []
|
||||
comb m (x:xs) = map (x:) (comb (m-1) xs) ++ comb m xs
|
||||
5
Task/Combinations/Haskell/combinations-2.hs
Normal file
5
Task/Combinations/Haskell/combinations-2.hs
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import Data.List (tails)
|
||||
|
||||
comb :: Int -> [a] -> [[a]]
|
||||
comb 0 _ = [[]]
|
||||
comb m l = [x:ys | x:xs <- tails l, ys <- comb (m-1) xs]
|
||||
1
Task/Combinations/Haskell/combinations-3.hs
Normal file
1
Task/Combinations/Haskell/combinations-3.hs
Normal file
|
|
@ -0,0 +1 @@
|
|||
comb0 m n = comb m [0..n-1]
|
||||
1
Task/Combinations/Haskell/combinations-4.hs
Normal file
1
Task/Combinations/Haskell/combinations-4.hs
Normal file
|
|
@ -0,0 +1 @@
|
|||
comb1 m n = comb m [1..n]
|
||||
2
Task/Combinations/Haskell/combinations-5.hs
Normal file
2
Task/Combinations/Haskell/combinations-5.hs
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
import Data.List (sort, subsequences)
|
||||
comb m n = sort . filter ((==m) . length) $ subsequences [0..n-1]
|
||||
1
Task/Combinations/Haskell/combinations-6.hs
Normal file
1
Task/Combinations/Haskell/combinations-6.hs
Normal file
|
|
@ -0,0 +1 @@
|
|||
comb m n = filter ((==m . length) $ filterM (const [True, False]) [0..n-1]
|
||||
12
Task/Combinations/Haskell/combinations-7.hs
Normal file
12
Task/Combinations/Haskell/combinations-7.hs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
comb :: Int -> [a] -> [[a]]
|
||||
comb m xs = combsBySize xs !! m
|
||||
where
|
||||
combsBySize = foldr f ([[]] : repeat [])
|
||||
f x next =
|
||||
zipWith
|
||||
(<>)
|
||||
(fmap (x :) <$> ([] : next))
|
||||
next
|
||||
|
||||
main :: IO ()
|
||||
main = print $ comb 3 [0 .. 4]
|
||||
Loading…
Add table
Add a link
Reference in a new issue