php - All possible combinations from sets -
i have set of numbers:
1,22 1,46 32,1 1,9 32,22 1,14 1,45 1,33 33,22 45,22 32,46 32,9 3,1 3,9 3,22 3,32 3,46 9,22 46,22 46,45 46,33 15,1 15,46 15,6 15,22 15,3 15,9 15,45 15,33 15,32 15,14
i need combinations them rule each new pair can appended if latter number same first in pair.
for example if have pair {15,1}, next on can {1,46} , next {46,45}, , final pair must end first number of whole set. in case example {45,1}.
so end result of sets 4 set limit
{15,1,1,46,46,45,45,1}
i can basic power sets , generate possible combinations set of numbers seems advanced me.
i can c, javascript or php or solutions highly appreciated. , clarification, not homework, learn , understand.
this looks if graph data structure, , graph algorithms, appropriate. graph comprise nodes (each of number) , edges (each of represents 1 of pairs). write appropriate routine walking round graph. it's not entirely clear question rules walk are, guess know.
edit
of course, should point out have graph data structure, it's called adjacency list. google around algorithms , representations.
Comments
Post a Comment