tasks a-s

This commit is contained in:
Ingy döt Net 2013-04-10 23:57:08 -07:00
parent 47bf37c096
commit b83f433714
12433 changed files with 156208 additions and 123 deletions

View file

@ -0,0 +1,9 @@
action p x = if p x then succ x else x
fenceM p q s [] = guard (q s) >> return []
fenceM p q s (x:xs) = do
(f,g) <- p
ys <- fenceM p q (g s) xs
return $ f x ys
ncsubseq = fenceM [((:), action even), (flip const, action odd)] (>= 3) 0

View file

@ -0,0 +1,4 @@
continuous = null . dropWhile not . dropWhile id . dropWhile not
ncs xs = map (map fst . filter snd . zip xs) $
filter (not . continuous) $
mapM (const [True,False]) xs

View file

@ -0,0 +1,10 @@
import Data.List
poset = foldr (\x p -> p ++ map (x:) p) [[]]
ncsubs [] = [[]]
ncsubs (x:xs) = tail $ nc [x] xs
where
nc [_] [] = [[]]
nc (_:x:xs) [] = nc [x] xs
nc xs (y:ys) = (nc (xs++[y]) ys) ++ map (xs++) (tail $ poset ys)

View file

@ -0,0 +1,8 @@
import Data.List (subsequences, tails, delete)
disjoint a = concatMap (cutAt a) [1..length a - 2] where
cutAt s n = [a ++ b | b <- delete [] (subsequences right),
a <- init (tails left) ] where
(left, _:right) = splitAt n s
main = print $ length $ disjoint [1..20]

View file

@ -0,0 +1,15 @@
import Data.List (inits, tails)
subseqs [] = []
subseqs (x:xs) = [x] : map (x:) s ++ s where s = subseqs xs
consecs x = concatMap (tail.inits) (tails x)
minus [] [] = []
minus (a:as) bb@(b:bs)
| a == b = minus as bs
| otherwise = a:minus as bb
disjoint s = (subseqs s) `minus` (consecs s)
main = mapM_ print $ disjoint [1..4]