Tag Info

New answers tagged

4

For lists of the size in the example, brute-forcing s/b fine: Module[{d = #1, m = #2, l = Length@#1, dt = (Tr@#1)/#2, dtp, parted}, parted = Internal`PartitionRagged[d, #] & /@ Join @@ Permutations /@ IntegerPartitions[l, {m}]; dtp = Total[Abs[Total[parted, {3}] - dt], {2}]; Pick[parted, dtp, Min@dtp]] &[data, 4] (* {{{16, 4, ...


0

data = {16, 4, 17, 10, 15, 4, 4, 6, 7, 14, 9, 17, 27, 6, 1, 9, 0, 12, 20, 8, 0, 3, 4, 0, 3, 4}; data1 = {}; i = 1; While[i < Length[data] && Total[data1] < 55, {data1 = Append[data1, x = Total[{Nearest[data, 55 - Total[data1]][[1]]}]], data = Delete[data, FirstPosition[data, x]]}; i++] data2 = {}; i = 1; While[i < Length[data] ...


1

Here's an overengineered approach using the method of simulated annealing. I apologize for the poor style of coding, this is something I had lying around found somewhere online and modified just now for this task. data = {16, 4, 17, 10, 15, 4, 4, 6, 7, 14, 9, 17, 27, 6, 1, 9, 0, 12, 20, 8, 0, 3, 4, 0, 3, 4}; Solution = Partition[Range@26, 7, 7, 1, {}]; ...


2

Here is a simple approach that splits the data into 4 sequences, with each sequence being as close to 55 as possible drop[list_, m_] := Drop[list, (Position[#, Sequence @@ Nearest[#, m]] &@ Accumulate@list)[[1, 1]]] take[list_, m_] := Take[list, (Position[#, Sequence @@ Nearest[#, m]] &@ Accumulate@list)[[1, 1]]] NestList[{take[#[[2]], 55], ...



Top 50 recent answers are included