Algorithm-X-DLX
view release on metacpan or search on metacpan
examples/polyomino/Shape.pm view on Meta::CPAN
646566676869707172737475767778798081828384
my
(
$self
) =
@_
;
my
@rows
=
map
{ [
reverse
@$_
] } @{
$self
->{bits}};
return
Shape->new(
$self
->{name}, \
@rows
);
}
sub
rotations {
my
(
$self
) =
@_
;
my
@result
= (
$self
);
my
$shape
=
$self
->rotate();
#TODO: compare shapes
while
(
$shape
->not_equals(
$result
[0])) {
push
@result
,
$shape
;
$shape
=
$shape
->rotate();
}
return
@result
;
}
sub
reflections {
my
(
$self
) =
@_
;
my
@refl
= (
$self
->reflect());
for
my
$rot
(
$self
->rotations()) {
examples/polyomino/Shape.pm view on Meta::CPAN
122123124125126127128129130131132133134135136137138139140141142use
Data::Dumper;
sub
equals {
my
(
$self
,
$rhs
) =
@_
;
#print Dumper($self->{content}), "\n == ? \n" , Dumper($rhs->{content});
#exit 0;
return
$self
->{content} eq
$rhs
->{content};
# return reduce { $a &&= $_ eq $_[2] } (map { $_ eq $_[2] } @{$rhs->{bits}}) == scalar(@{$rhs->{bits}});
}
sub
not_equals {
my
(
$self
,
$rhs
) =
@_
;
return
!(
$self
->equals(
$rhs
));
}
sub
less_than {
my
(
$self
,
$rhs
) =
@_
;
return
join
(
','
,
map
{
join
(
','
,
@$_
) } @{
$self
->{bits}}) lt
join
(
','
,
map
{
join
(
','
,
@$_
) } @{
$rhs
->{bits}});
}
1;
# End of package return true;
examples/sudoku/Sudoku.pm view on Meta::CPAN
99100101102103104105106107108109110111112113114115116117118119}
sub
array_equals {
my
(
$a1
,
$a2
) =
@_
;
# a replacement for the smartmatch operator '~~', giving warnings (experimental) since 5.18
# optional modules: List::Compare, Array::Compare, Data::Compare
my
$match
=
@$a1
==
@$a2
&& !
grep
{ !
$_
}
map
{
$a1
->[
$_
] eq
$a2
->[
$_
] } 0 ..
$#$a1
;
return
$match
}
sub
not_equals {
my
(
$self
,
$other
) =
@_
;
return
!(
$self
->equals(
$other
));
}
sub
to_string {
my
(
$self
) =
@_
;
return
$self
->to_string_format(SudokuFormat->new(
$self
->{type_}));
}
sub
to_string_format {
( run in 0.372 second using v1.01-cache-2.11-cpan-87723dcf8b7 )