| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Algorithm::MasterMind::Sequential_Alt; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
868
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
36
|
|
|
4
|
1
|
|
|
1
|
|
4
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
36
|
|
|
5
|
1
|
|
|
1
|
|
4
|
use Carp; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
50
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
4
|
use lib qw(../../lib); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
5
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = sprintf "%d.%03d", q$Revision: 1.3 $ =~ /(\d+)\.(\d+)/g; |
|
10
|
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
154
|
use base 'Algorithm::MasterMind'; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
89
|
|
|
12
|
1
|
|
|
1
|
|
4
|
use Algorithm::Combinatorics qw(variations_with_repetition); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
350
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub initialize { |
|
15
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
|
16
|
1
|
|
33
|
|
|
3
|
my $options = shift || croak "Need options here"; |
|
17
|
1
|
|
|
|
|
4
|
for my $o ( keys %$options ) { |
|
18
|
2
|
|
|
|
|
12
|
$self->{"_$o"} = $options->{$o} |
|
19
|
|
|
|
|
|
|
} |
|
20
|
1
|
|
|
|
|
3
|
my @alphabet = @{$self->{'_alphabet'}}; |
|
|
1
|
|
|
|
|
4
|
|
|
21
|
1
|
|
|
|
|
3
|
my @tebahpla = reverse @alphabet; |
|
22
|
1
|
|
|
|
|
7
|
$self->{'_engine_fw'} = variations_with_repetition(\@alphabet, $options->{'length'}); |
|
23
|
1
|
|
|
|
|
53
|
$self->{'_engine_bw'} = variations_with_repetition(\@tebahpla, $options->{'length'}); |
|
24
|
1
|
|
|
|
|
30
|
$self->{'_current_min'} = $alphabet[0]x$options->{'length'}; |
|
25
|
1
|
|
|
|
|
3
|
$self->{'_current_max'} = $tebahpla[0]x$options->{'length'}; |
|
26
|
1
|
|
|
|
|
22
|
$self->{'_direction'} = 1; # Forward, 0 for backwards |
|
27
|
|
|
|
|
|
|
} |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub issue_next { |
|
30
|
4
|
|
|
4
|
1
|
7
|
my $self = shift; |
|
31
|
4
|
|
|
|
|
11
|
my $rules = $self->number_of_rules(); |
|
32
|
4
|
|
|
|
|
7
|
my ($match, $string); |
|
33
|
4
|
|
66
|
|
|
5
|
do { |
|
34
|
1225
|
100
|
|
|
|
2144
|
if ( $self->{'_direction'} ) { |
|
35
|
50
|
|
|
|
|
52
|
$string = join("",@{$self->{'_engine_fw'}->next}); |
|
|
50
|
|
|
|
|
155
|
|
|
36
|
50
|
|
|
|
|
516
|
$self->{'_current_min'} = $string; |
|
37
|
|
|
|
|
|
|
} else { |
|
38
|
1175
|
|
|
|
|
1202
|
$string = join("",@{$self->{'_engine_bw'}->next}); |
|
|
1175
|
|
|
|
|
3372
|
|
|
39
|
1175
|
|
|
|
|
11677
|
$self->{'_current_max'} = $string; |
|
40
|
|
|
|
|
|
|
} |
|
41
|
1225
|
|
|
|
|
2744
|
$match = $self->matches($string); |
|
42
|
|
|
|
|
|
|
} while ( ( $self->{'_current_min'} lt $self->{'_current_max'} ) |
|
43
|
|
|
|
|
|
|
&& $match->{'matches'} < $rules ); |
|
44
|
4
|
|
|
|
|
12
|
$self->{'_direction'} = !$self->{'_direction'}; |
|
45
|
4
|
|
|
|
|
28
|
return $self->{'_last'} = $string; |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
"some blacks, 0 white"; # Magic true value required at end of module |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
__END__ |