Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View 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

View 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]

View file

@ -0,0 +1 @@
comb0 m n = comb m [0..n-1]

View file

@ -0,0 +1 @@
comb1 m n = comb m [1..n]

View file

@ -0,0 +1,2 @@
import Data.List (sort, subsequences)
comb m n = sort . filter ((==m) . length) $ subsequences [0..n-1]

View file

@ -0,0 +1 @@
comb m n = filter ((==m . length) $ filterM (const [True, False]) [0..n-1]

View 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]