Rafting Problem (Knapsack variant) First puzzle from me, suggestions for improvement gladly received!

The scenario is;
You work as a manager for a whitewater rafting company. Every morning, you are given a list of bookings, and you have to sort them into raft loads. Write a program or function in your chosen language that does this for you.

Each raft holds a maximum of n clients, and each booking is for a group of between 1 and n people (inclusive).
The following rules must be observed;


No groups may be split up. If they booked together, they must all be in the same raft.
The number of rafts must be minimised.
Subject to the two preceeding rules, the groups must be spread as equally as possible between the rafts.


Inputs.
The number n (you may assume that this is a positive integer), and the size of all the bookings. This may be an array, list or similar data structure if your language supports such things. All of these will be positive integers between 1 and n. The order of the bookings is not defined, nor is it important.

Output.
A list of the booking numbers, grouped into raft loads. The grouping must be indicated unambiguously, such as;


a list, or array of arrays.
a comma separated list for each raft. Newline between each raft.


How you implement the third rule is up to you, but this could involve finding the average raft occupancy, and minimising deviations from it as much as possible. Here are some test cases.

n  Bookings       Output
6  [2,5]          [5],[2]
4  [1,1,1,1,1]    [1,1,1],[1,1]
6  [2,3,2]        [2,2],[3]
6  [2,3,2,3]      [2,3],[2,3]
6  [2,3,2,3,2]    [2,2,2],[3,3]
12 [10,8,6,4,2]   [10],[8,2],[6,4]
6  [4,4,4]        [4],[4],[4]
12 [12,7,6,6]     [12],[7],[6,6]


Standard rules apply, shortest code wins. Have fun!

Edited;
A suggested way to define as equally as possible for the third rule.

Once the number of rafts r has been determined (subject to the second rule), the average occupancy a can be calculated by summing over the bookings, and dividing by r. For each raft, the deviation from the average occupancy can be found using d(x) = abs(n(x)-a), where n(x) is the number of people in each raft and 1 &lt;= x &lt;= r.
For some continuous, single-valued function f(y), which is strictly positive and has a strictly positive first and non-negative second derivatives for all positive y, we define a non-negative quantity F, as the sum of all the f(d(x)), 1 &lt;= x &lt;= r. Any choice of raft allocation that satisfies the first two rules, and where F is equal to the global minimum will satisfy the third rule also.
Haskell 226 228 234 268 bytes

Naive answer in Haskell



import Data.List
o=map
u=sum
p=foldr(\x t-&gt;o([x]:)t++[(x:y):r|(y:r)&lt;-t&gt;&gt;=permutations])[[]]
m x=foldl(\[m,n]x-&gt;[m+(x-m)/(n+1),n+1])[0,0]x!!0
a!z=abs$u z-a
s t=(length t,u$o((m$o u t)!)t)
a n=head.sortOn s.filter(all$(&lt;=n).u).p


Or ungolfed

partition' :: [a] -&gt; [[[a]]]
partition' [] = [[]]
partition' (x:xs) = [[x]:ps     | ps &lt;- partition' xs]
                 ++ [(x:p):rest | ps &lt;- partition' xs, (p:rest) &lt;- permutations ps]

-- from Data.Statistics
mean :: [Double] -&gt; Double
mean xs = fst $ foldl (\(m, n) x -&gt; (m+(x-m)/n+1, n+1)) (0, 0) xs

diff :: Double -&gt; [Double] -&gt; Double
diff avg xs = abs $ sum xs - avg

rawScore :: [[Double]] -&gt; Double
rawScore xs = sum . map (diff avg) $ xs where avg = mean . map sum $ xs

score :: [[Double]] -&gt; (Int, Double)
score xs = (length xs, rawScore xs)

-- from Data.Ord
comparing :: (Ord b) =&gt; (a -&gt; b) -&gt; a -&gt; a -&gt; Ordering
comparing p x y = compare (p x) (p y)

candidates :: Double -&gt; [Double] -&gt; [[[Double]]]
candidates n xs = filter (all (\ ys -&gt; sum ys &lt;= n)) . partition' $ xs

answer :: Double -&gt; [Double] -&gt; [[Double]]
answer n xs = minimumBy (comparing score) $ candidates n xs


With some test cases

import Text.PrettyPrint.Boxes

testCases :: [(Double, [Double])]
testCases = [(6 , [2,5])
            ,(4 , [1,1,1,1,1])
            ,(6 , [2,3,2])
            ,(6 , [2,3,2,3])
            ,(6 , [2,3,2,3,2])
            ,(12, [10,8,6,4,2])
            ,(6 , [4,4,4])
            ,(12, [12,7,6,6])]

runTests tests = transpose 
                 $ ["n", "Bookings", "Output"]
                 : map (\(n, t) -&gt; [ show . floor $ n
                                   , show . map floor $ t
                                   , show . map (map floor) $ a n t]) tests

test = printBox 
     . hsep 3 left . map (vcat top) . map (map text) . runTests $ testCases


Where test yields

n    Bookings       Output
6    [2,5]          [[2],[5]]
4    [1,1,1,1]      [[1,1],[1,1,1]]
6    [2,3,2]        [[2,2],[3]]
6    [2,3,2,3]      [[2,3],[2,3]]
6    [2,3,2,3,2]    [[2,2,2],[3,3]]
12   [10,8,6,4,2]   [[10],[8,2],[6,4]]
6    [4,4,4]        [[4],[4],[4]]
12   [12,7,6,6]     [[12],[7],[6,6]]


Edit

Thanks to @flawr and @nimi for advice.

Squashed p a bit.

Shaved off a couple bytes.