line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!perl |
2
|
1
|
|
|
1
|
|
978
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
33
|
|
3
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
45
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# SEE THE END OF THIS FILE FOR AUTHOR, COPYRIGHT AND LICENSE INFORMATION |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
{ package Algorithm::Odometer::Gray; |
8
|
|
|
|
|
|
|
our $VERSION = "0.04"; |
9
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
115
|
|
10
|
|
|
|
|
|
|
use overload '<>' => sub { |
11
|
24
|
|
|
24
|
|
654
|
my $self = shift; |
12
|
24
|
100
|
|
|
|
58
|
return $self->() unless wantarray; |
13
|
1
|
|
|
|
|
3
|
my @all; |
14
|
1
|
|
|
|
|
3
|
while (defined( my $x = $self->() )) |
15
|
6
|
|
|
|
|
17
|
{ push @all, $x } |
16
|
1
|
|
|
|
|
11
|
return @all; |
17
|
1
|
|
|
1
|
|
8
|
}; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
18
|
|
|
|
|
|
|
sub new { ## no critic (RequireArgUnpacking) |
19
|
6
|
|
|
6
|
0
|
4342
|
my $class = shift; |
20
|
6
|
|
|
|
|
22
|
return bless odometer_gray(@_), $class; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
sub odometer_gray { ## no critic (RequireArgUnpacking) |
23
|
6
|
100
|
|
6
|
0
|
102
|
croak "no wheels specified" unless @_; |
24
|
5
|
|
|
|
|
15
|
my @w = @_; |
25
|
|
|
|
|
|
|
croak "all wheels must have at least two positions" |
26
|
5
|
100
|
|
|
|
10
|
if grep {@$_<2} @w; |
|
11
|
|
|
|
|
278
|
|
27
|
3
|
|
|
|
|
10
|
my @c = (0) x @w; |
28
|
3
|
|
|
|
|
8
|
my @f = 0 .. @w; |
29
|
3
|
|
|
|
|
7
|
my @o = (1) x @w; |
30
|
3
|
|
|
|
|
6
|
my $done; |
31
|
|
|
|
|
|
|
return sub { |
32
|
33
|
100
|
|
33
|
|
1401
|
if ($done) { @c = (0) x @w; @f = 0 .. @w; @o = (1) x @w; $done=0; return } |
|
3
|
|
|
|
|
15
|
|
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
8
|
|
33
|
30
|
|
|
|
|
56
|
my @cur = map {$w[$_][$c[$_]]} 0..$#w; |
|
78
|
|
|
|
|
187
|
|
34
|
30
|
100
|
|
|
|
68
|
if ($f[0]==@w) { $done=1 } |
|
3
|
|
|
|
|
6
|
|
35
|
|
|
|
|
|
|
else { |
36
|
27
|
|
|
|
|
40
|
my $j = $f[0]; $f[0] = 0; |
|
27
|
|
|
|
|
38
|
|
37
|
27
|
|
|
|
|
37
|
$c[$j] += $o[$j]; |
38
|
27
|
100
|
100
|
|
|
58
|
if ( $c[$j]==0 || $c[$j]==$#{$w[$j]} ) { |
|
20
|
|
|
|
|
66
|
|
39
|
18
|
|
|
|
|
30
|
$o[$j] = -$o[$j]; |
40
|
18
|
|
|
|
|
31
|
$f[$j] = $f[$j+1]; |
41
|
18
|
|
|
|
|
29
|
$f[$j+1] = $j+1; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
30
|
100
|
|
|
|
72
|
return wantarray ? @cur : join '', map {defined()?$_:''} @cur; |
|
75
|
100
|
|
|
|
314
|
|
45
|
3
|
|
|
|
|
22
|
}; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
1; |
50
|
|
|
|
|
|
|
__END__ |