Algorithm-X-DLX
view release on metacpan or search on metacpan
examples/sudoku/SudokuFormat.pm view on Meta::CPAN
1234567891011121314151617package
SudokuFormat;
use
strict;
use
warnings;
sub
new {
my
(
$class
,
$type_or_format
,
$input
) =
@_
;
my
$self
= {};
if
(
$input
&& !
ref
(
$input
)) {
$self
->{template} =
$input
;
}
if
(
ref
(
$type_or_format
) eq
'SudokuType'
) {
examples/sudoku/SudokuFormat.pm view on Meta::CPAN
47484950515253545556575859606162636465666768697071727374757677sub
compact {
my
(
$class
,
$type
) =
@_
;
my
$line
=
'.'
x
$type
->n() .
"\n"
;
my
$result
=
''
;
for
(
my
$y
= 0;
$y
<
$type
->n(); ++
$y
) {
$result
.=
$line
;
}
my
$self
= {
type
=>
$type
,
template
=>
$result
,
labels
=> choose_labels(
$result
) };
weaken(
$self
->{type});
return
bless
$self
,
$class
;
}
sub
oneline {
my
(
$class
,
$type
) =
@_
;
my
$result
=
'.'
x
$type
->size() .
"\n"
;
my
$self
= {
type
=>
$type
,
template
=>
$result
,
labels
=> choose_labels(
$result
) };
weaken(
$self
->{type});
return
bless
$self
,
$class
;
}
sub
with_labels {
my
(
$self
,
$str
) =
@_
;
my
@labels
= choose_labels_n(
$str
,
scalar
split
//,
$self
->{type}->n());
my
%new_self
= %{
$self
};
@new_self
{
qw(labels)
} =
@labels
;
( run in 0.312 second using v1.01-cache-2.11-cpan-a9ef4e587e4 )