Skip to content

Commit b5cca40

Browse files
authored
Merge pull request #13166 from mattmartini/branch-for-challenge-349
Solutions for challenge 349
2 parents 2a5350f + 8e5fa38 commit b5cca40

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

challenge-349/matt-martini/README

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Solution by Matt Martini
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env perl
2+
3+
use 5.018;
4+
use strict;
5+
use warnings;
6+
use Test2::V0;
7+
8+
plan tests => 5;
9+
10+
sub meeting_point {
11+
my $path = shift;
12+
my %path_count = ( U => 0, D => 0, L => 0, R => 0 );
13+
14+
print "$path\n";
15+
16+
my $result = 'false';
17+
STEP:
18+
while ( $path =~ m|(.)|g ) {
19+
my $step = $1;
20+
$path_count{ $step }++;
21+
22+
if ( ( $path_count{ U } == $path_count{ D } )
23+
&& ( $path_count{ L } == $path_count{ R } ) )
24+
{
25+
$result = 'true';
26+
last STEP;
27+
}
28+
}
29+
say $result;
30+
31+
return $result;
32+
}
33+
34+
is( meeting_point('ULD'), 'false', 'example 1' );
35+
is( meeting_point('ULDR'), 'true', 'example 2' );
36+
is( meeting_point('UUURRRDDD'), 'false', 'example 3' );
37+
is( meeting_point('UURRRDDLLL'), 'true', 'example 4' );
38+
is( meeting_point('RRUULLDDRRUU'), 'true', 'example 5' );

0 commit comments

Comments
 (0)