line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Games::Sudoku::Component::Base;
|
2
|
|
|
|
|
|
|
{
|
3
|
7
|
|
|
7
|
|
46
|
use strict;
|
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
252
|
|
4
|
7
|
|
|
7
|
|
39
|
use warnings;
|
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
879
|
|
5
|
7
|
|
|
7
|
|
38
|
use Carp;
|
|
7
|
|
|
|
|
23
|
|
|
7
|
|
|
|
|
5321
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.01';
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new {
|
10
|
1145
|
|
|
1145
|
1
|
8478
|
my $class = shift;
|
11
|
1145
|
|
33
|
|
|
5542
|
my $this = bless {}, (ref $class || $class);
|
12
|
|
|
|
|
|
|
|
13
|
1145
|
50
|
|
|
|
4607
|
my %options = ref $_[0] ? %{ $_[0] } : @_;
|
|
0
|
|
|
|
|
0
|
|
14
|
|
|
|
|
|
|
|
15
|
1145
|
|
100
|
|
|
3761
|
my $size = $options{size} || 0;
|
16
|
1145
|
|
100
|
|
|
2442
|
my $bl_width = $options{block_width} || 0;
|
17
|
1145
|
|
100
|
|
|
2259
|
my $bl_height = $options{block_height} || 0;
|
18
|
|
|
|
|
|
|
|
19
|
1145
|
100
|
66
|
|
|
7186
|
if ($bl_width and $bl_height and $bl_width && $bl_height) {
|
|
|
100
|
33
|
|
|
|
|
|
|
50
|
66
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
20
|
1133
|
|
|
|
|
1312
|
$size = $bl_width * $bl_height;
|
21
|
|
|
|
|
|
|
}
|
22
|
|
|
|
|
|
|
elsif ($size and $size == int(sqrt($size)) ** 2) {
|
23
|
5
|
|
|
|
|
22
|
$bl_width = $bl_height = int(sqrt($size));
|
24
|
|
|
|
|
|
|
}
|
25
|
|
|
|
|
|
|
elsif ($size or $bl_width or $bl_height) {
|
26
|
0
|
0
|
|
|
|
0
|
croak "Invalid size: $size" if $size;
|
27
|
0
|
0
|
0
|
|
|
0
|
croak "Invalid block: width $bl_width, height $bl_height"
|
28
|
|
|
|
|
|
|
if $bl_width || $bl_height;
|
29
|
|
|
|
|
|
|
}
|
30
|
|
|
|
|
|
|
else {
|
31
|
7
|
|
|
|
|
15
|
$size = 9;
|
32
|
7
|
|
|
|
|
15
|
$bl_width = $bl_height = 3;
|
33
|
|
|
|
|
|
|
}
|
34
|
|
|
|
|
|
|
|
35
|
1145
|
|
|
|
|
8028
|
$this->{size} = $size;
|
36
|
1145
|
|
|
|
|
2078
|
$this->{block_width} = $bl_width;
|
37
|
1145
|
|
|
|
|
1362
|
$this->{block_height} = $bl_height;
|
38
|
|
|
|
|
|
|
|
39
|
1145
|
|
|
|
|
4320
|
$this->_initialize(%options);
|
40
|
|
|
|
|
|
|
|
41
|
1145
|
|
|
|
|
5176
|
$this;
|
42
|
|
|
|
|
|
|
}
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub _initialize {
|
45
|
0
|
|
|
0
|
|
0
|
my ($this, %options) = @_;
|
46
|
|
|
|
|
|
|
}
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub _check {
|
49
|
311411
|
|
|
311411
|
|
369861
|
my ($this, $value) = @_;
|
50
|
|
|
|
|
|
|
|
51
|
311411
|
50
|
|
|
|
585306
|
croak "Invalid value: undef" unless defined $value;
|
52
|
311411
|
50
|
33
|
|
|
1199099
|
croak "Invalid value: $value" if $value > $this->{size} || $value < 1;
|
53
|
|
|
|
|
|
|
|
54
|
311411
|
|
|
|
|
860317
|
$value;
|
55
|
|
|
|
|
|
|
}
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub _check0 {
|
58
|
868
|
|
|
868
|
|
1210
|
my ($this, $value) = @_;
|
59
|
|
|
|
|
|
|
|
60
|
868
|
50
|
|
|
|
1934
|
croak "Invalid value: undef" unless defined $value;
|
61
|
868
|
50
|
33
|
|
|
3920
|
croak "Invalid value: $value" if $value > $this->{size} || $value < 0;
|
62
|
|
|
|
|
|
|
|
63
|
868
|
|
|
|
|
2704
|
$value;
|
64
|
|
|
|
|
|
|
}
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub _block_id {
|
67
|
66154
|
|
|
66154
|
|
79418
|
my ($this, $row, $col) = @_;
|
68
|
|
|
|
|
|
|
|
69
|
66154
|
50
|
|
|
|
116324
|
croak "Invalid row: $row" unless $this->_check($row);
|
70
|
66154
|
50
|
|
|
|
127004
|
croak "Invalid col: $col" unless $this->_check($col);
|
71
|
|
|
|
|
|
|
|
72
|
66154
|
|
|
|
|
125565
|
my $blockrow = int(($row - 1) / $this->{block_height});
|
73
|
66154
|
|
|
|
|
97340
|
my $blockcol = int(($col - 1) / $this->{block_width});
|
74
|
|
|
|
|
|
|
|
75
|
66154
|
|
|
|
|
184008
|
$blockrow * $this->{block_height} + $blockcol + 1;
|
76
|
|
|
|
|
|
|
}
|
77
|
|
|
|
|
|
|
|
78
|
21
|
|
|
21
|
1
|
4694
|
sub size { $_[0]->{size} }
|
79
|
9
|
|
|
9
|
1
|
3744
|
sub block_width { $_[0]->{block_width} }
|
80
|
9
|
|
|
9
|
1
|
4205
|
sub block_height { $_[0]->{block_height} }
|
81
|
|
|
|
|
|
|
}
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
1;
|
84
|
|
|
|
|
|
|
__END__
|