V
V
Vladimir Miroshnik2020-07-06 16:46:37
PHP
Vladimir Miroshnik, 2020-07-06 16:46:37

How to equally divide the elements of an array among other arrays?

There is an initial array A - it contains 1500 unique numbers.

The task is to get 400 arrays containing 30 numbers from array A, so that each number from array A occurs the same number of times.

The code will be in php, but would I understand the scheme? Especially if the number of array elements can change.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
nokimaro, 2020-07-06
@Q0Q

In a loop, extract a random string from array A , and place it in the target array while deleting it from A
And so on until A becomes empty. If A becomes empty, then we restore its original state (1500 rows) and continue decomposing random rows into target arrays.
And so on in a circle until we fill all the target arrays.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question