aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Muth <matthias.muth@gmx.de>2024-09-28 22:36:35 +0200
committerMatthias Muth <matthias.muth@gmx.de>2024-09-28 22:44:00 +0200
commit0f32114efbdb5375b08606058280e73ed248029d (patch)
tree124f95f16740ed40bf8ac1d58ac474f41a5058cd
parentde956e6ce1bb55bfd2d5a300a895fc1e7fb7fcd1 (diff)
downloadperlweeklychallenge-club-0f32114efbdb5375b08606058280e73ed248029d.tar.gz
perlweeklychallenge-club-0f32114efbdb5375b08606058280e73ed248029d.tar.bz2
perlweeklychallenge-club-0f32114efbdb5375b08606058280e73ed248029d.zip
Challenge 288 Task 1 and 2 solutions in Perl by Matthias Muth -
Cosmetics
-rwxr-xr-xchallenge-288/matthias-muth/perl/ch-1.pl3
-rwxr-xr-xchallenge-288/matthias-muth/perl/ch-2b.pl106
2 files changed, 0 insertions, 109 deletions
diff --git a/challenge-288/matthias-muth/perl/ch-1.pl b/challenge-288/matthias-muth/perl/ch-1.pl
index 394bf7eeba..1036cfe9d1 100755
--- a/challenge-288/matthias-muth/perl/ch-1.pl
+++ b/challenge-288/matthias-muth/perl/ch-1.pl
@@ -10,9 +10,6 @@
use v5.36;
-our $verbose = 0;
-sub vsay( @args ) { say @args if $verbose };
-
sub closest_palindrome_1( $str ) {
# Searching in two directions: down and up, until we find a number
# that is a palindrome.
diff --git a/challenge-288/matthias-muth/perl/ch-2b.pl b/challenge-288/matthias-muth/perl/ch-2b.pl
deleted file mode 100755
index b44e8cf412..0000000000
--- a/challenge-288/matthias-muth/perl/ch-2b.pl
+++ /dev/null
@@ -1,106 +0,0 @@
-#!/usr/bin/env perl
-#
-# The Weekly Challenge - Perl & Raku
-# (https://theweeklychallenge.org)
-#
-# Challenge 288 Task 2: Contiguous Block
-#
-# Perl solution by Matthias Muth.
-#
-
-use v5.36;
-
-use List::Util qw( max );
-use Algorithm::Loops qw( NestedLoops );
-
-sub flood_and_mark( $matrix, $r, $c, $visited ) {
- $visited->[$r][$c] = 1;
- my @neighbors = (
- $r > 0 ? ( $r - 1, $c ) : (),
- $c > 0 ? ( $r, $c - 1 ) : (),
- $c < $matrix->[$r]->$#* ? ( $r, $c + 1 ) : (),
- $r < $matrix->$#* ? ( $r + 1, $c ) : (),
- );
- my $symbol = $matrix->[$r][$c];
- my $count = 1; # For this field itself.
- for my ( $next_r, $next_c ) ( @neighbors ) {
- next
- if $matrix->[$next_r][$next_c] ne $symbol
- || $visited->[$next_r][$next_c];
- $count += flood_and_mark( $matrix, $next_r, $next_c, $visited );
- }
- return $count;
-}
-
-sub contiguous_block( $matrix ) {
- my @visited;
- my $max = 0;
-
- my @rows = ( 0..$matrix->$#* ); # row indices
- my @columns = ( 0..$matrix->[0]->$#* ); # column indices
- my $iterator = NestedLoops( [ \@rows, \@columns ] );
- while ( my ( $r, $c ) = $iterator->() ) {
- if ( ! $visited[$r][$c] ) {
- my $area = flood_and_mark( $matrix, $r, $c, \@visited );
- $max = $area
- if $area > $max;
- }
- }
- return $max;
-}
-
-use Test2::V0 qw( -no_srand );
-is contiguous_block( [
- ["x", "x", "x", "x", "o"],
- ["x", "o", "o", "o", "o"],
- ["x", "o", "o", "o", "o"],
- ["x", "x", "x", "o", "o"],
-] ), 11,
- 'Example 1: contiguous_block( [
- ["x", "x", "x", "x", "o"],
- ["x", "o", "o", "o", "o"],
- ["x", "o", "o", "o", "o"],
- ["x", "x", "x", "o", "o"],
-] ) == 11';
-is contiguous_block( [
- ["x", "x", "x", "x", "x"],
- ["x", "o", "o", "o", "o"],
- ["x", "x", "x", "x", "o"],
- ["x", "o", "o", "o", "o"],
-] ), 11,
- 'Example 2: contiguous_block( [
- ["x", "x", "x", "x", "x"],
- ["x", "o", "o", "o", "o"],
- ["x", "x", "x", "x", "o"],
- ["x", "o", "o", "o", "o"],
-] ) == 11';
-is contiguous_block( [
- ["x", "x", "x", "o", "o"],
- ["o", "o", "o", "x", "x"],
- ["o", "x", "x", "o", "o"],
- ["o", "o", "o", "x", "x"],
-] ), 7,
- 'Example 3: contiguous_block( [
- ["x", "x", "x", "o", "o"],
- ["o", "o", "o", "x", "x"],
- ["o", "x", "x", "o", "o"],
- ["o", "o", "o", "x", "x"],
-] ) == 7';
-
-is contiguous_block( [
- ["x", "o", "x", "o", "x"],
- ["o", "x", "o", "x", "o"],
- ["x", "o", "x", "o", "x"],
- ["o", "x", "o", "x", "o"],
-] ), 1,
- 'Extra 1: contiguous_block( [
- ["x", "o", "x", "o", "x"],
- ["o", "x", "o", "x", "o"],
- ["x", "o", "x", "o", "x"],
- ["o", "x", "o", "x", "o"],
-] ) == 1';
-
-is contiguous_block( [] ), 0,
- 'Extra 2: contiguous_block( [] ) == 0';
-
-done_testing;