nGroups :: Int -> [Package] -> [[[Package]]]
nGroups n pkgs = do
  group1 <- bestGroups limit pkgs
  otherGroups <- takeGroups (n - 1) (pkgs \\ group1)
  let groups = group1 : otherGroups in do
    guard (length pkgs == length (concat groups))
    return groups
  where
    limit = totalWeight pkgs `div` n
    takeGroups 0 _  = return []
    takeGroups i ps = do
      g <- groupsOfWeight limit ps
      (g:) <$> takeGroups (i-1) (ps \\ g)
nGroups :: Int -> [Package] -> [[[Package]]]
nGroups n pkgs = do
  group1 <- bestGroups limit pkgs
  otherGroups <- takeGroups (n - 1) (pkgs \\ group1)
  let groups = group1 : otherGroups in do
    guard (length pkgs == length (concat groups))
    return groups
  where
    limit = totalWeight pkgs `div` n
    takeGroups 0 _  = return []
    takeGroups i ps = do
      g <- groupsOfWeight limit ps
      (g:) <$> takeGroups (i-1) (ps \\ g)
nGroups n pkgs = do
  group1 <- bestGroups limit pkgs
  otherGroups <- takeGroups (n - 1) (pkgs \\ group1)
  let groups = group1 : otherGroups in do
    guard (length pkgs == length (concat groups))
    return groups
  where
    limit = totalWeight pkgs `div` n
    takeGroups 0 _  = return []
    takeGroups i ps = do
      g <- groupsOfWeight limit ps
      (g:) <$> takeGroups (i-1) (ps \\ g)