aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-285/nelo-tovar/perl/ch-1.pl40
-rw-r--r--challenge-285/nelo-tovar/perl/ch-2.pl39
2 files changed, 79 insertions, 0 deletions
diff --git a/challenge-285/nelo-tovar/perl/ch-1.pl b/challenge-285/nelo-tovar/perl/ch-1.pl
new file mode 100644
index 0000000000..d6dd07af1f
--- /dev/null
+++ b/challenge-285/nelo-tovar/perl/ch-1.pl
@@ -0,0 +1,40 @@
+#!/usr/bin/env perl
+
+# The Weekly Challenge 285 - By Nelo Tovar
+#
+# https://theweeklychallenge.org/blog/perl-weekly-challenge-285/
+#
+# Task 1 - No Connection
+#
+
+use strict;
+use warnings;
+use v5.28;
+use Data::Dump qw(dump);
+
+my @examples = (
+ [ ["B","C"], ["D","B"], ["C","A"] ],
+ [ ["A","Z"] ],
+);
+
+sub no_connection {
+ my $routes = shift;
+ my @departures = map {$_->[0]} @$routes;
+ my @arrivals = map {$_->[1]} @$routes;
+
+ foreach my $a (@arrivals) {
+ my $temp = scalar grep { $_ eq $a } @departures;
+
+ return $a if ( scalar $temp eq 0 )
+ }
+
+ return ''
+}
+
+for my $elements (@examples) {
+ my $nc = no_connection $elements;
+
+ say 'Input : @routes = ', dump(@$elements);
+ say 'Output : ', $nc;
+ say ' ';
+}
diff --git a/challenge-285/nelo-tovar/perl/ch-2.pl b/challenge-285/nelo-tovar/perl/ch-2.pl
new file mode 100644
index 0000000000..639f3aab9e
--- /dev/null
+++ b/challenge-285/nelo-tovar/perl/ch-2.pl
@@ -0,0 +1,39 @@
+#!/usr/bin/env perl
+
+# The Weekly Challenge 285 - By Nelo Tovar
+#
+# https://theweeklychallenge.org/blog/perl-weekly-challenge-285/
+#
+# Task 2 - Making Change
+#
+
+use strict;
+use warnings;
+use v5.28;
+use List::Util qw (min max);
+use Algorithm::Combinatorics qw(combinations);
+use Data::Dump qw(dump);
+
+my @examples = ( 9, 15, 100 );
+
+sub making_change {
+ my $amount = shift;
+ my @coins = (1, 5, 10, 25, 50);
+ my @changes = (1);
+
+ foreach my $coin (@coins){
+ for my $i (0 .. $amount - $coin){
+ $changes[$i + $coin] += $changes[$i];
+ }
+ }
+
+ return $changes[$amount]
+}
+
+for my $elements (@examples) {
+ my $mc = making_change $elements;
+
+ say 'Input : $amount = ', $elements;
+ say 'Output : ', $mc;
+ say ' ';
+}