Algorithm-X-DLX

 view release on metacpan or  search on metacpan

examples/sudoku/SudokuFormat.pm  view on Meta::CPAN

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
package SudokuFormat;
 
use strict;
use Carp qw(croak);
use List::Util qw(first);
use Scalar::Util qw(weaken);
 
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

47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
sub 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 )