diff options
Diffstat (limited to 'challenge-285/matthias-muth/perl/ch-1.pl')
| -rwxr-xr-x | challenge-285/matthias-muth/perl/ch-1.pl | 11 |
1 files changed, 2 insertions, 9 deletions
diff --git a/challenge-285/matthias-muth/perl/ch-1.pl b/challenge-285/matthias-muth/perl/ch-1.pl index 1e31b14e52..ef36f1c3a4 100755 --- a/challenge-285/matthias-muth/perl/ch-1.pl +++ b/challenge-285/matthias-muth/perl/ch-1.pl @@ -10,20 +10,13 @@ use v5.36; -sub no_connection( $routes ) { - # Store all given routes in a hash ( from => to ). - my %from_to = map { $_->[0] => $_->[1] } $routes->@*; - # Return the first 'to' node that does not have a route going out of it. - return ( grep { ! exists $from_to{$_} } values %from_to )[0]; -} - -use List::Util qw( unpairs ); +use List::Util qw( unpairs first ); sub no_connection( $routes ) { # Store all given routes in a hash ( from => to ). my %connections = unpairs $routes->@*; # Return the first destination node that does not have a route going out of it. - return ( grep { ! exists $connections{$_} } values %connections )[0]; + return first { ! exists $connections{$_} } values %connections; } use Test2::V0 qw( -no_srand ); |
