# Non-Constant Partitioning of a List with Order Analysis [duplicate]

Let's say I have a set of numbers "r" whose sum equals 15, and I want to randomize all values up to and including that sum from and including 1 into a set called "a". So far I have this:

r = {4,5,6}
ord = Range
a = RandomSample[ord]


And though for everyone the evaluation would yield a randomly different answer each time, for me the answer was:

{4,5,6}
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}
{13,2,8,15,7,12,14,3,11,1,6,5,9,4,10}


Now, half of the challenge I'm stuck on is how to Partition "a" (the last line of the output above) in the consecutive amounts of the set "r" ({4,5,6}), such that the output next would look like:

{{13,2,8,15},{7,12,4,3,11},{1,6,5,9,4,10}} // Lengths 4,5,6 respectively


Lastly I want the Ordering function applied to each of these subsets in one fell stroke, so that the final output derived from the above line would be:

{{2,3,1,4},{4,3,1,5,2},{1,5,3,2,4,6}}


Of course the answer would look different depending on what random sample was generated, but I need the logic to be consistent with what's here outlined.

Thanks!

• b=InternalPartitionRagged[a, r] and Ordering/@b?
– kglr
Mar 29 '17 at 23:37
• @kglr That is exactly right, thanks so much! Very elegant : ] Mar 29 '17 at 23:41
• @kglr this is great! what is "InternalPartitionRagged" I can't find any documentation Mar 29 '17 at 23:48
• @Jenny, it is an undocumented function. Try Information[InternalPartitionRagged] for a description of what it does.
– kglr
Mar 29 '17 at 23:52

SeedRandom
r = {4, 5, 6};
ord = Range;
a = RandomSample[ord]


{14, 2, 5, 1, 8, 12, 10, 13, 15, 11, 9, 4, 7, 6, 3}

b = InternalPartitionRagged[a, r]


or, if you have version 10 or a newer version

b = FoldPairList[TakeDrop,a,r]


both give

{{14, 2, 5, 1}, {8, 12, 10, 13, 15}, {11, 9, 4, 7, 6, 3}}

And

Ordering /@ b


{{4, 2, 3, 1}, {1, 3, 2, 4, 5}, {6, 3, 5, 4, 2, 1}}