Chuỗi bài: haskell
haskell
9 dòng
· Cập nhật 2026-02-03
extension_2.hs
haskell/Week_6_Lab/extension_2.hs
-- Define the rucksack function
rucksack :: [Integer] -> Integer -> [[Integer]]
rucksack [] target
| target == 0 = [[]] -- Base case: if the target is 0, return a list containing an empty list
| otherwise = [] -- If the target is not 0, return an empty list
rucksack (x:xs) target =
let withoutX = rucksack xs target -- Subsets excluding x
withX = rucksack xs (target - x) -- Subsets including x
in withoutX ++ map (x:) withX -- Combine both cases
Bài viết liên quan
haskell
haskell
Cập nhật 2026-02-03
Adding.hs
Adding.hs — haskell source code from the haskell learning materials (haskell/Adding.hs).
Đọc bài viết →
haskell
haskell
Cập nhật 2026-02-03
Area.hs
Area.hs — haskell source code from the haskell learning materials (haskell/Area.hs).
Đọc bài viết →
haskell
haskell
Cập nhật 2026-02-03
Chess.hs
Chess.hs — haskell source code from the haskell learning materials (haskell/Chess.hs).
Đọc bài viết →
haskell
haskell
Cập nhật 2026-02-03
ChessGraphics.hs
ChessGraphics.hs — haskell source code from the haskell learning materials (haskell/ChessGraphics.hs).
Đọc bài viết →
haskell
haskell
Cập nhật 2026-02-03
Examples.hs
Examples.hs — haskell source code from the haskell learning materials (haskell/Examples.hs).
Đọc bài viết →
haskell
haskell
Cập nhật 2026-02-03
Fibonacci.hs
Fibonacci.hs — haskell source code from the haskell learning materials (haskell/Fibonacci.hs).
Đọc bài viết →