M
M
MasterCopipaster2020-10-28 20:19:02
Algorithms
MasterCopipaster, 2020-10-28 20:19:02

A quick way to select all possible variations of array values, what are the ways?

Good day, I have an array of 3 elements
I want to get all possible combinations from this array:

массив: 'A','B','C' 
Комбинации:
A
B
C
A B
A C
B C 
A B C


The trouble is that I have this array of 179 elements, and it's impossible to sort through all possible combinations using the simple enumeration method (it takes too much time) are there algorithms that allow me to do this not by simply enumerating the options?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Pankov, 2020-10-29
@MasterCopipaster

Judging by the statement of the problem and the example, we are not talking about all possible values ​​of the array, but about all possible subsets of the set with a power of 179.
If each element of the superset can either be included or not included, then each of the sets can be compared with a 179-bit binary number. Obviously, there are 2^179 such numbers. If we remove the empty set from the set (there was none in the example), then there will be one less choice: 2^179-1.
In the decimal system, this is so many options: 766247770432944429179173513575154591809369561091801087
The author of the question does not say exactly how he wants to get all these options, but in any case it is impossible to save such a number of elements, in our Sun there are only about a hundred times more atoms than this number. Feeling trouble, right?
But the problem must be solved somehow. Let's use the Gray code so that when moving from option to option, we can limit ourselves to changing just one bit. But even this will not help us to sort through all the options in a reasonable time.
Suppose that we need insanely little time for one option: one cycle of the processor. We will not save the options anywhere (it would take ten Jupiters to write all the options on their atoms), we will just show it on the screen. Yes, this will not work in one cycle, but imagine that we have such a special processor with a frequency of 3 gigahertz. And we need 8099185802817355231125623242284335104 years of his work.
And it's all pointless. Protso the author of the question does not understand what he wants.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question