diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-09-07 18:55:17 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-07 18:55:17 +0100 |
| commit | 8c07dc964c1314a2c8dce356d65d161d8882a5d1 (patch) | |
| tree | b08ac6b8b24508250d40479ce44efa4254b0c47b | |
| parent | 143a3da53e2b0dec5c4e62213f729c648f27f28b (diff) | |
| parent | 44ec1ff8f4d8a8348ac0f5b10a12760744f7ab08 (diff) | |
| download | perlweeklychallenge-club-8c07dc964c1314a2c8dce356d65d161d8882a5d1.tar.gz perlweeklychallenge-club-8c07dc964c1314a2c8dce356d65d161d8882a5d1.tar.bz2 perlweeklychallenge-club-8c07dc964c1314a2c8dce356d65d161d8882a5d1.zip | |
Merge pull request #10785 from ntovar/branch-285
Challenge 285. Add Perl solutions. By Nelo Tovar
| -rw-r--r-- | challenge-285/nelo-tovar/perl/ch-1.pl | 40 | ||||
| -rw-r--r-- | challenge-285/nelo-tovar/perl/ch-2.pl | 39 |
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 ' '; +} |
