File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed
challenge-349/matt-martini Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change 1+ Solution by Matt Martini
Original file line number Diff line number Diff line change 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' );
You can’t perform that action at this time.
0 commit comments