Fix combination bug with small inventories
This commit is contained in:
+12
-2
@@ -18,9 +18,19 @@ powlistUpToN' n (x:xs)
|
||||
-- there is a (probably) faster SO answer that produces power lists of size
|
||||
-- exactly N, but that answer is harder to adapt
|
||||
powlistUpToN :: Int -> [a] -> [[a]]
|
||||
powlistUpToN n xs =
|
||||
powlistUpToN n xs = concat $ drop (length xs-n) (subseqsBySize xs)
|
||||
where
|
||||
subseqsBySize [] = [[[]]]
|
||||
subseqsBySize (y:ys) =
|
||||
let next = subseqsBySize ys
|
||||
in zipWith (++) ([]:next) (map (map (y:)) next ++ [[]])
|
||||
powlistUpToN'' :: Int -> [a] -> [[a]]
|
||||
powlistUpToN'' n xs =
|
||||
let l = length xs
|
||||
in if n > l then [] else concat $ drop (l-n) (subseqsBySize xs)
|
||||
-- in if n > l then [] else concat $ drop (l-n) (subseqsBySize xs)
|
||||
in if n > l
|
||||
then concat $ subseqsBySize xs
|
||||
else concat $ drop (l-n) (subseqsBySize xs)
|
||||
where
|
||||
subseqsBySize [] = [[[]]]
|
||||
subseqsBySize (y:ys) =
|
||||
|
||||
Reference in New Issue
Block a user