From 8e5fa38785b4f1dabe2e99a5c9b5e699eaf7ac61 Mon Sep 17 00:00:00 2001 From: Matt Martini Date: Thu, 11 Dec 2025 15:28:25 -0500 Subject: [PATCH] Solutions for challenge 349 --- challenge-349/matt-martini/README | 1 + challenge-349/matt-martini/perl/ch-2.pl | 38 +++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 challenge-349/matt-martini/README create mode 100644 challenge-349/matt-martini/perl/ch-2.pl diff --git a/challenge-349/matt-martini/README b/challenge-349/matt-martini/README new file mode 100644 index 0000000000..4407e4c65b --- /dev/null +++ b/challenge-349/matt-martini/README @@ -0,0 +1 @@ +Solution by Matt Martini diff --git a/challenge-349/matt-martini/perl/ch-2.pl b/challenge-349/matt-martini/perl/ch-2.pl new file mode 100644 index 0000000000..6dabccb209 --- /dev/null +++ b/challenge-349/matt-martini/perl/ch-2.pl @@ -0,0 +1,38 @@ +#!/usr/bin/env perl + +use 5.018; +use strict; +use warnings; +use Test2::V0; + +plan tests => 5; + +sub meeting_point { + my $path = shift; + my %path_count = ( U => 0, D => 0, L => 0, R => 0 ); + + print "$path\n"; + + my $result = 'false'; + STEP: + while ( $path =~ m|(.)|g ) { + my $step = $1; + $path_count{ $step }++; + + if ( ( $path_count{ U } == $path_count{ D } ) + && ( $path_count{ L } == $path_count{ R } ) ) + { + $result = 'true'; + last STEP; + } + } + say $result; + + return $result; +} + +is( meeting_point('ULD'), 'false', 'example 1' ); +is( meeting_point('ULDR'), 'true', 'example 2' ); +is( meeting_point('UUURRRDDD'), 'false', 'example 3' ); +is( meeting_point('UURRRDDLLL'), 'true', 'example 4' ); +is( meeting_point('RRUULLDDRRUU'), 'true', 'example 5' );