A
A
Aler2011-12-15 10:26:09
Python
Aler, 2011-12-15 10:26:09

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

6 answer(s)
A
Ano, 2011-12-15
@Aler

Nested loops are, of course, equivalent, but in python it would be ideologically correct
import itertools
itertools.product( ('1', '2', '3'), repeat=6)

G
Gregory, 2011-12-15
@difiso

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.

V
Vyacheslav Plisko, 2011-12-15
@AmdY

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.

V
Vladimir Martyanov, 2011-12-16
@vilgeforce

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 question

Ask a Question

731 491 924 answers to any question