Answer the question
In order to leave comments, you need to log in
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
What's the problem? The search is trivial.
for (i = 1; i < 10000; i++) {
for (j = i+1; j <= 10000; j++) {
// пара [i, j]
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question