CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
how to skip redundant permutations?

 



gevni
Novice

Nov 22, 2012, 2:01 PM

Post #1 of 3 (1342 views)
how to skip redundant permutations? Can't Post

Hi
I have this function that will exclude the redundant permutations. If processes are adjacent and belongs to same group exclude this permutation order. I need to change it like it will check all the processes that belongs to same group and skip all these combination weather they are adjacent or not but belongs to the same group like that :

position: 0, 1,2,3
a ,a,b,a
here all a belongs to same group and b belongs to different group.
this function will exclude the permutation that interchange position 0 (a) to position 1 (a) and i want to modify it like it will exclude all the permutations weather they are adjacent or not like it may exclude position 0(a) to position 3(a) permutation order too . Function is


sub Apply_on_index(&@)
{
my $func = shift;
my $array = shift;
my $group = shift;
return undef unless (defined $func and defined $array);
my $rest;
my $i;
my $j;
my @array;
my $size = $#{$array}+1;
my $card = factorial($size);
my $res;
for($j=0;$j<$card;$j++){
@array = @{$array};
$res = [];
$rest = $j;
$i = 0;
for($i = 0; $i <= $#{$array}; $i++){
${$res}[$i] = splice @array, $rest % ($#array + 1), 1;
$rest = int($rest / ($#array + 2));
if ($i > 0 and ${$res}[$i] < ${$res}[$i-1] and
${$group}[${$res}[$i]] == ${$group}[${$res}[$i-1]]){
$res = undef;
last;
}
}
&$func($j) if defined $res;
}
return 0;
}
Plz let me know how I can modify it?


Laurent_R
Veteran / Moderator

Nov 23, 2012, 3:56 AM

Post #2 of 3 (1300 views)
Re: [gevni] how to skip redundant permutations? [In reply to] Can't Post

Please post your code within code tags, so that we can hopefully see the indentation and formating.


gevni
Novice

Nov 23, 2012, 5:40 AM

Post #3 of 3 (1292 views)
Re: [Laurent_R] how to skip redundant permutations? [In reply to] Can't Post


In Reply To
i post my question in new thread with code tag as here it won't allow me edit.


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives