I believe that it may be simplified, but I have no ideas anymore.. I need to flatten inside each element of array. F.ex. {{1}, 128552, 6, 1} ---> {1, 128552, 6, 1}
Input data (Z - requests, t - periods of time):
Z = {{ 1, 3, 3, 7}, {8, 6, 6, 3}, {3, 5, 6, 13}, {15, 15, 9, 4}, {1, 1, 3, 6}, {9, 4, 3, 2}} t = {{129600, 30240}, {30240, 10080}, {10080, 1440}, {1440, 0}} I need to generate time of each request, then number of product (1-6), then sort it and give the index number of requst and in the end append 1.
My decision:
MapIndexed[Prepend[Append[#, 1], #2] &, Sort[Flatten[Table[Partition[Append[Riffle[ RandomInteger[t[[i]], Z[[j, i]]], j], j], 2], {j, 6}, {i, 4}], 2], #1[[1]] > #2[[1]] &]] It's part of the answer:
{{{1}, 128559, 3, 1}, {{2}, 128229, 6, 1}, {{3}, 127041, 4, 1},....,{{151}, 34, 3, 1}, {{152}, 18, 4, 1}} I don't know how to simplify my decision..
Flatten[{#2, #, 1}] &instead ofPrepend[Append...]&in the first argument ofMapIndexed.. $\endgroup$