Algorithm-X-DLX

 view release on metacpan or  search on metacpan

examples/polyomino/Shape.pm  view on Meta::CPAN

64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
  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

122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
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

99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
}
 
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 )