Thread Buchstaben generieren: Bruteforce-aehnlich (14 answers)
Opened by styx-cc at 2006-11-03 00:46

topeg
 2006-11-04 21:09
#71322 #71322
User since
2006-07-10
2611 Artikel
BenutzerIn

user image
Nun das ganze mal von "Hand" :-)
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/perl
use strict;
use warnings;

my ($stellen,@elemente)=@ARGV;
die "Aufruf:\n $0 stellen element_a [element_b [element_c [ ...]]]\n" if(@elemente==0 || $stellen!~/^\d+$/);

sub permutation($@)
{
my ($st,@arr) = @_;
my @ret=();
my @cnt=map{$_=0}(1..$st);
ende:while(1)
{
push(@ret,join('',map{$_=$arr[$_]}@{[@cnt]}));
for my $i (0..$st-1)
{
if($cnt[$i]<@arr-1)
{
$cnt[$i]++;
last;
}
else
{
$cnt[$i]=0;
last(ende) unless( exists($cnt[$i+1]) );
}
}
}
return @ret;
}

print "Elemente: ".join('; ', @elemente)."\n";
print "Stellen: $stellen\n";
print "Variantionen:\n";
print join("\n",&permutation($stellen,@elemente)),"\n";

View full thread Buchstaben generieren: Bruteforce-aehnlich