aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2020-11-10 12:37:01 +0100
committerAbigail <abigail@abigail.be>2020-11-10 12:37:01 +0100
commitd20ec35a96dc969d2e474457fc38e05e9d4b300a (patch)
treef8fe10b12575c17f13a8d4c4c75bf1d157175df7
parentff5eeef6b91878ded37e9644c84212cc8333b632 (diff)
downloadperlweeklychallenge-club-d20ec35a96dc969d2e474457fc38e05e9d4b300a.tar.gz
perlweeklychallenge-club-d20ec35a96dc969d2e474457fc38e05e9d4b300a.tar.bz2
perlweeklychallenge-club-d20ec35a96dc969d2e474457fc38e05e9d4b300a.zip
Sudokus could be any size (assuming a square size)
-rw-r--r--challenge-086/abigail/perl/ch-2.pl8
1 files changed, 6 insertions, 2 deletions
diff --git a/challenge-086/abigail/perl/ch-2.pl b/challenge-086/abigail/perl/ch-2.pl
index 7763d1ea76..ce25f5dcab 100644
--- a/challenge-086/abigail/perl/ch-2.pl
+++ b/challenge-086/abigail/perl/ch-2.pl
@@ -12,20 +12,24 @@ use experimental 'lexical_subs';
#
# Read the puzzle; set unsolved squares to 0.
+# This read any sized sudoku.
#
-my @sudoku = map {[map {/_/ ? 0 : $_} /[_1-9]/g]} <>;
+my @sudoku = map {[map {/_/ ? 0 : $_} /\b(?:_|[1-9][0-9]*)\b/g]} <>;
my $SIZE = @sudoku;
my @INDICES = (0 .. $SIZE - 1);
my @ELEMENTS = (1 .. $SIZE);
my $sqrtSIZE = sqrt $SIZE;
#
-# Sanity check
+# Sanity checks
#
die "Sudoku width not a square\n"
unless int (sqrt $SIZE) ** 2 == $SIZE;
die "All rows should be the same length as the columns"
if grep {@$_ != $SIZE} @sudoku;
+foreach my $row (@sudoku) {
+ die "Elements should not exceed $SIZE" if grep {$_ > $SIZE} @$row;
+}
#
# Given a square with coordinates ($x, $y), return all the