| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Math::Sequence::DeBruijn; |
|
2
|
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
449620
|
use 5.028; |
|
|
4
|
|
|
|
|
22
|
|
|
4
|
4
|
|
|
4
|
|
24
|
use strict; |
|
|
4
|
|
|
|
|
7
|
|
|
|
4
|
|
|
|
|
160
|
|
|
5
|
4
|
|
|
4
|
|
22
|
use warnings; |
|
|
4
|
|
|
|
|
23
|
|
|
|
4
|
|
|
|
|
283
|
|
|
6
|
4
|
|
|
4
|
|
24
|
no warnings 'syntax'; |
|
|
4
|
|
|
|
|
24
|
|
|
|
4
|
|
|
|
|
186
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
4
|
|
|
4
|
|
742
|
use experimental 'signatures'; |
|
|
4
|
|
|
|
|
3175
|
|
|
|
4
|
|
|
|
|
26
|
|
|
9
|
4
|
|
|
4
|
|
655
|
use experimental 'lexical_subs'; |
|
|
4
|
|
|
|
|
7
|
|
|
|
4
|
|
|
|
|
12
|
|
|
10
|
4
|
|
|
4
|
|
140
|
use Exporter (); |
|
|
4
|
|
|
|
|
6
|
|
|
|
4
|
|
|
|
|
1968
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '2022021301'; |
|
13
|
|
|
|
|
|
|
our @EXPORT = qw [debruijn]; |
|
14
|
|
|
|
|
|
|
our @ISA = qw [Exporter]; |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# |
|
18
|
|
|
|
|
|
|
# This a translation of the Python program given at the Wikipedia |
|
19
|
|
|
|
|
|
|
# page on De Bruijn sequences. |
|
20
|
|
|
|
|
|
|
# (https://en.wikipedia.org/wiki/De_Bruijn_sequence) |
|
21
|
|
|
|
|
|
|
# |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub debruijn ($alphabet, $n) { |
|
24
|
|
|
|
|
|
|
$alphabet = [split // => $alphabet] unless ref $alphabet; |
|
25
|
|
|
|
|
|
|
my $size = @$alphabet; |
|
26
|
|
|
|
|
|
|
my @a = (0) x ($size * $n); |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my $sequence = []; |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my sub db ($t, $p) { |
|
31
|
|
|
|
|
|
|
if ($t > $n) { |
|
32
|
|
|
|
|
|
|
push @$sequence => @a [1 .. $p] if $n % $p == 0; |
|
33
|
|
|
|
|
|
|
} |
|
34
|
|
|
|
|
|
|
else { |
|
35
|
|
|
|
|
|
|
$a [$t] = $a [$t - $p]; |
|
36
|
|
|
|
|
|
|
__SUB__ -> ($t + 1, $p); |
|
37
|
|
|
|
|
|
|
foreach my $j ($a [$t - $p] + 1 .. ($size - 1)) { |
|
38
|
|
|
|
|
|
|
$a [$t] = $j; |
|
39
|
|
|
|
|
|
|
__SUB__ -> ($t + 1, $t); |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
}; |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
db (1, 1); |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
join "" => @$alphabet [@$sequence]; |
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
1; |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
__END__ |