Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- divide rounding up
- (/^) :: Int -> Int -> Int
- x /^ y = (x + y - 1) `div` y
- -- all values must be at positive, must be sorted by descending value!
- test = reverse [(1,7), (2,4), (3,2), (4,2)] :: [(Int, Int)]
- target = 7 :: Int
- -- Given the remaining input, current partial solution and remaining target
- -- returns a possible skinny pack represented by its multiplicities in the list
- -- monad.
- skinnies :: [(Int, Int)] -> [(Int, Int)] -> Int -> [[(Int, Int)]]
- -- leaf case, need to cover the bin without any extra
- skinnies [(v,m)] cs t | t /^ v <= m = return ((v,max 0 (t/^v)) : cs)
- | otherwise = []
- skinnies ((v,m) : vms) cs t = do
- c <- [0 .. t /^ v] -- don't pick more than necessary
- skinnies vms ((v,c) : cs) (t - c * v)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement