Thread permutation (31 answers)
Opened by esskar at 2006-09-11 12:30

esskar
 2006-09-12 10:56
#69633 #69633
User since
2003-08-04
7321 Artikel
ModeratorIn

user image
interessante lösung
obwohl sie abe mehr als neun bindestrichen nicht mehr funktioniert; hier die etwas gecleante lösung

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
my $len = $str =~ tr/-//;
my $max = (2 ** $len) - 1;
my $pat = '^' . '([^-]*)-' x $len . '([^-]*)$';
       
for my $i ( 0 .. $max ) {
           
  my $bits = sprintf("%03b", $i);
                                   
  my $subs = '';
  $subs .= '$' . ($_+1) . ((($bits >> $_) & 0x1) ? '-' : '')
     for (0 .. $len-1);
  $subs .= '$'.($len+1);
           
  my $tmp;
  eval("(\$tmp = '$str') =~ s/$pat/$subs/;");
           
  push @retval, $tmp;                        
}                


gibts noch andere lösungen?\n\n

<!--EDIT|esskar|1158044216-->

View full thread permutation