Fix combination bug with small inventories

This commit is contained in:
2022-03-04 00:11:36 +00:00
parent ae219f2ddf
commit 2961923534
3 changed files with 18 additions and 7 deletions
+12 -2
View File
@@ -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) =