Answer the question
In order to leave comments, you need to log in
How to find all combinations of characters?
There is an array of characters - ['a', 'b', 'c'].
You need to make permutations (?) of them in order to get all variants of 3x3 matrices from these symbols:
[ ['a', 'a', 'a'], ['a', 'a', 'a'], ['a', 'a', 'a']],
,
,
...,
[ ['a', 'b', 'c'], ['a', 'b', 'c'], ['a', 'b', 'c']],
...,
[ ['c', 'c', 'c'], ['c', 'c', 'c'], ['c', 'c', 'c']]
print list(itertools.product(['a', 'b', 'c'], repeat=9))
Answer the question
In order to leave comments, you need to log in
Such matrices seem to describe possible binary operations on the set {'a','b','c'}, i.e. functions of two variables from this set, taking values in the same set.
There will be 3^9=19683 such functions in total. Therefore, it is enough to sort through the numbers from 0 to 3 ^ 9-1, and turn the ternary record of each of them into a matrix. In C# it would look like this:
char[,] matr=new char[3,3];
for(int i=0;i<19683;i++){
int a=i;
for(int j=9;--j>=0;){
matr[j/3,j%3]=(char)('a'+a%3);
a/=3;
}
Process(matr);
}
From such a task, I would decide that at first they are interested in all permutations inside this row (selection without return) - there will be 6 of them.
And then from the resulting 6 rows, make up all possible variants of square matrices (selection with return) - respectively, there will be 6 ^ 3 = 216.
The lexicographical first square matrix will be [abc, abc, abc], then [abc, abc, acb], [abc, abc, bac], ..., and it will end with [cba, cba, cab], [cba, cba , cba].
Implementation of a roughly similar algorithm in PHP: What is the best way to make a code for translation?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question