E
E
EchoStan2019-07-04 22:57:53
Mathematics
EchoStan, 2019-07-04 22:57:53

How to write an algorithm that returns all possible combinations of array elements?

Given:
Data structure with nested arrays looks like this (js):

[ 
[ 1,2,3],
[ 4,5,6],
[ 7, 8, 9]
]

Need to: Construct one array with all combinations of int-values, one value from each subarray i.e.
[
[1,4,7],
[1,4,8],
[1,4,9],
[1,5,7]
...

Never a mathematician, my head is boiling)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
longclaps, 2019-07-04
@EchoStan

javascript cartesian product

O
orbit070, 2019-07-04
@orbit070

You are essentially asking to write a solution for you, and probably even someone will do it, but this is prohibited by the rules of this site. You can ask for help and tips, but do not solve problems for you.
To solve the problem, you do not need to be a mathematician, but you just need to read about nested loops and analyze a few examples, of which there are a million on the Internet.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question