[1..100]>>=pen #4915(2007/12/21 09:40 GMT) [ Haskell ] Rating1/1=1.00
comb の方にも和の制約を入れたら手元のマシンで magic 5 のケースが4倍速になりました。
1 2 3 4 5 6 7 8 9 10 11 12 13
comb :: Int -> Int -> [Int] -> [([Int],[Int])] comb s _ xs | s < 0 = [] comb s 0 xs | s == 0 = [([],xs)] | otherwise = [] comb _ _ [] = [] comb s k (x:xs) = [ (x:ys,zs) | (ys,zs) <- comb (s-x) (k-1) xs ] ++[ (ys,x:zs) | (ys,zs) <- comb s k xs ] comb' :: Int -> Int -> [Int] -> [([Int],[Int])] comb' s 0 xs | s == 0 = [([],xs)] | otherwise = [] comb' _ _ [] = [] comb' s k (x:xs) = [ (x:ys,zs) | (ys,zs) <- comb (s-x) (k-1) xs ]
Rating1/1=1.00-0+
1 reply [ reply ]
[1..100]>>=pen
#4915()
[
Haskell
]
Rating1/1=1.00
Rating1/1=1.00-0+