X
X
xolova2020-09-14 16:12:12
Combinatorics
xolova, 2020-09-14 16:12:12

How to iterate over combinations with a large number of numbers?

There is a script that iterates over the numbers in the specified range in pairs and without repetitions. For example: the numbers 1-2-3-4 will output the result [1-2][1-3][1-4][2-3][2-4][3-4].
Everything works well, but there are times when you need to iterate over the numbers from 1 to 10.000, and then the script simply can not cope with such a number. How can you optimally iterate over such a number of numbers?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2020-09-14
@xolova

What's the problem? The search is trivial.

for (i = 1; i < 10000;  i++) {
  for (j = i+1; j <= 10000; j++) {
    // пара [i, j]
  }
}

Another thing is that with 10000 numbers you will get 10000*9999/2 = 49'995'000 pairs.
That is, you need to speed up the processing of each pair and parallelize the calculations.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question