Advertisement
Guest User

Untitled

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