#!/usr/local/bin/perl use Games::Sudoku::General; use Getopt::Long; my $usage = <new (); my $fh = $opt{demo} ? *DATA : *STDIN; my $puzzle = ''; print "\nInput:\n"; while (<$fh>) { print; next if m/^\s*$/ || m/^\s*#/; my ($name, $value) = m/^\s*-set\s+(\S+)\s+(.*)/ or do { $puzzle .= $_; next; }; chomp $value; $su->set ($name, $value); } $su->problem ($puzzle); print "\nSolution:\n"; if (my $soln = $su->solution ()) { print $soln, "\nConstraints used: ", scalar $su->constraints_used, "\n"; } else { print "No solution found.\n"; } __DATA__ # The following -set is optional, since this is the default setting. -set sudoku 3 # Spaces are optional in the following, as are line breaks. ...4..789 4.6...1.. .8.....5. 2.4..5... .95...... 6..9.2.4. .3..7.9.8 .67...... 9....8..2