-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcombination.pl
More file actions
100 lines (88 loc) · 1.36 KB
/
combination.pl
File metadata and controls
100 lines (88 loc) · 1.36 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#! perl -w
#generate all the possible combinations of letter
use strict;
my @ori=('a'..'k');
my @tree=('=');
@tree=addone(@tree);
for my $i (1..11){
my @top10;
for my $j (0..9){
$top10[$j]=$tree[$j];
}
for my $t (@top10){
print $i.$t."\n";
}
@tree=addone(@top10);
}
sub addone{
my (@group)=@_;
my @new=();
for my $i (@group){
my @used=split /,/,$i;
my @left=remove(@used);
for my $j (@left){
push @new,$i.",".$j;
}
}
return unique(@new);
#return @new;
}
sub remove{
my (@del)=@_;
my $end=-1;
for(my $i=0;$i<=$#ori;$i++){
if($del[$#del] eq $ori[$i]){
$end=$i;
last;
}
}
my @unused=();
for(my $i=$end+1;$i<=$#ori;$i++){
push @unused,$ori[$i];
}
my @left=();
for my $i (@unused){
my $flag=0;
for my $j (@del){
if ($i eq $j){
$flag=1;
last;
}
}
push @left,$i if($flag==0);
}
return @left;
}
sub remove2{
my (@del)=@_;
my @left=();
for my $i (@ori){
my $flag=0;
for my $j (@del){
if ($i eq $j){
$flag=1;
last;
}
}
push @left,$i if($flag==0);
}
return @left;
}
sub unique{
my(@all)=@_;
for my $temp (@all){
$temp=join(",", (sort {$a cmp $b} split /,/,$temp));
}
for(my $i=0;$i<$#all;$i++){
for(my $j=$i+1;$j<=$#all;$j++){
if($all[$i] eq $all[$j]){
$all[$j]="#";
}
}
}
my @one=();
for my $temp (@all){
push @one,$temp if $temp ne "#";
}
return @one;
}