Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

permutation generator

Status
Not open for further replies.

Denster

Programmer
Apr 9, 2001
198
GB
could someone help with a project I am trying to do based on numbers generated for the national Lottery. I want to be able to enter 10 numbers then display the possible permutations for a line of six. There should be a possible 210 permutations. I've spent many a sleepless night over this but keep getting lost with the amount of loops involved. Is there an easier way?. Any guidance would be apreciated.
 
Hi denster,
Can you please elaborate your program like:
Input req. 1 2 3 4 5 6 7 8 9 0
output expected :
1234567890
1345678902
1456678923
is this way u want it or something else????

So pls specify the req. properly.
Regards,
SwapSawe.
 
No! input 1,2,3,4,5,6,7,8,9,10
output 1,2,3,4,5,6
7,2,3,4,5,6
1,7,3,4,5,6
1,2,7,4,5,6....
and so on until all possible 210 variations have been produced. All numbers to be used but generate only lines of six. Line number 210 should be 1,2,7,8,9,10 or something similar. Hope I've explained this a bit better, its driving me nuts!!!.
 
I've managed to get it working with Perl ... primarily because I'm bad at writing C. :)

I've included the main routine in Perl below.
Code:
use vars qw/ $m $n $x $y $z @p @chars @set /;

@chars = qw/ a b c d e /;

$m = 3; #number elements in combinations
$n = 6; #number of total elements + 1
@p = ();

inittwiddle($m,$n,\@p);

while(!twiddle(\$x,\$y,\$z,\@p)) {
    $set[$z] = $chars[$x];
    print @set,"\n" if scalar(@set) == $m;
}

inittwiddle() and twiddle() are simply Perl interpretations of the same C code you see.

Hope this helps,

brendanc@icehouse.net
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top