Algorithm-X-DLX

 view release on metacpan or  search on metacpan

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


    my $value_size = scalar(@values);
    my $type_size = $self->type->size();
    croak "to_string(): wrong number of values ($value_size vs. $type_size)" if $value_size != $type_size;
    
    my @result_chars = split //, $self->{template};
    
    my $j = 0;
    for (my $i=0; $i < @result_chars; ++$i) {
        if (is_cell($result_chars[$i], $self)) {
            croak "Logic error" if (@values <= $j);
            $result_chars[$i] = label($values[$j], $self);
            $j++;
        }
    }        

    croak "Logic error" if (@values != $j);
        
    return join('', @result_chars);
}

sub type {
   return shift->{type};
}

sub is_empty {
   my $c = shift;

lib/Algorithm/X/Examples.pod  view on Meta::CPAN

The first one can actually be either a secondary or a primary column; if all other conditions are met, every cell will naturally contain I<at most one> digit.

Each row of the matrix hits exactly one column of each type.

For the standard 9x9 Sudoku, all regions are 3x3 squares. But it is straight-forward to generalize this so that the regions can form an arbitrary partition of the grid to subsets of size n. This also makes it possible to create Sudokus of any size; w...

=head3 Usage

The executable tries to infer as much as possible from the input data, requiring no flags or meta data about the Sudoku types. It expects to find Sudokus separated by empty lines. Empty cells can be either dots (C<'.'>) or zeros (C<'0'>). All non-zer...

The given Sudokus will be solved, unless they are invalid or unsolvable; in that case, an error message is printed. A completely empty Sudoku will be replaced with a randomly generated (and usually quite difficult) one, which is also solved.

=head3 Examples

  examples/sudoku$ perl -I. ./sudoku.pl < ../data/sudoku.txt*
  
  examples/sudoku$ perl -I. ./sudoku.pl -s -l -f oneline < sudoku17** > sudoku17_solutions
  
  examples/sudoku$ yes . | head -n81 | perl -I. ./sudoku.pl -f default

(E<nbsp>*) L<input|https://metacpan.org/dist/Algorithm-X-DLX/source/examples/data/sudoku.txt>,  L<output|https://metacpan.org/dist/Algorithm-X-DLX/source/examples/sudoku/output.txt>



( run in 0.782 second using v1.01-cache-2.11-cpan-65fba6d93b7 )