Answer the question
In order to leave comments, you need to log in
Combinatorial Algorithms
Recommend an article on a subject with an implementation for n-objects in m-cells (preferably in python)
PS I want to make a list of color codes for the texture set prerender for cubes, that is, the code where 1 is red, 2 is yellow and 3 is green, and the final code looks something like this: "122311".
P.S. Did I count correctly? What if there are 6 cells (6 faces) and 3 colors, then in the final there are 216 combinations (6 ^ 3)
Answer the question
In order to leave comments, you need to log in
Nested loops are, of course, equivalent, but in python it would be ideologically correct
import itertools
itertools.product( ('1', '2', '3'), repeat=6)
Regarding PPS. You counted wrong. The number of such combinations is 3^6 = 729 - a ternary number system with six positions.
If we talk only about cubes, then not 729, but less, because some combinations can be obtained from others by a simple turn.
not right. you need a number system (3 colors) to raise to a power of bit depth (6 cells). easy to remember when compared with the familiar decimal system. a system of 10 digits 3, respectively, 1000 options.
in your version, you can stupidly do three cycles and not “bother” with the permutation algorithm.
If you need a full enumeration, a good algorithm is described here www.wasm.ru/article.php?article=cycle_pwd
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question