diff options
| -rw-r--r-- | challenge-001/paulo-custodio/stats.pl | 3 | ||||
| -rw-r--r-- | challenge-285/paulo-custodio/Makefile | 2 | ||||
| -rw-r--r-- | challenge-285/paulo-custodio/perl/ch-1.pl | 43 | ||||
| -rw-r--r-- | challenge-285/paulo-custodio/perl/ch-2.pl | 63 | ||||
| -rw-r--r-- | challenge-285/paulo-custodio/t/test-1.yaml | 10 | ||||
| -rw-r--r-- | challenge-285/paulo-custodio/t/test-2.yaml | 15 |
6 files changed, 135 insertions, 1 deletions
diff --git a/challenge-001/paulo-custodio/stats.pl b/challenge-001/paulo-custodio/stats.pl index 6e8b69719d..1ff3a450ce 100644 --- a/challenge-001/paulo-custodio/stats.pl +++ b/challenge-001/paulo-custodio/stats.pl @@ -40,11 +40,12 @@ for my $chall_dir (path(".")->children(qr/challenge-\d+/)) { } } -# challenge 232 did not happen +# challenge 232 did not exist for my $lang (sort keys %LANG) { $sols[232]{$lang} = 2; } + # output for my $chall (1 .. $#sols) { if (($chall) % 10 == 1) { diff --git a/challenge-285/paulo-custodio/Makefile b/challenge-285/paulo-custodio/Makefile new file mode 100644 index 0000000000..c3c762d746 --- /dev/null +++ b/challenge-285/paulo-custodio/Makefile @@ -0,0 +1,2 @@ +all: + perl ../../challenge-001/paulo-custodio/test.pl diff --git a/challenge-285/paulo-custodio/perl/ch-1.pl b/challenge-285/paulo-custodio/perl/ch-1.pl new file mode 100644 index 0000000000..c91b661a60 --- /dev/null +++ b/challenge-285/paulo-custodio/perl/ch-1.pl @@ -0,0 +1,43 @@ +#!/usr/bin/env perl + +# Challenge 285 +# +# Task 1: No Connection +# Submitted by: Mohammad Sajid Anwar +# +# You are given a list of routes, @routes. +# +# Write a script to find the destination with no further outgoing connection. +# Example 1 +# +# Input: @routes = (["B","C"], ["D","B"], ["C","A"]) +# Output: "A" +# +# "D" -> "B" -> "C" -> "A". +# "B" -> "C" -> "A". +# "C" -> "A". +# "A". +# +# Example 2 +# +# Input: @routes = (["A","Z"]) +# Output: "Z" + +use Modern::Perl; + +my @routes = map {[split ' ', $_]} split /,/, "@ARGV"; +say join ", ", endpoints(@routes); + +sub endpoints { + my(@routes) = @_; + my %endpoints; + for (@routes) { + my($a, $b) = @$_; + $endpoints{$b}=1; + } + for (@routes) { + my($a, $b) = @$_; + delete $endpoints{$a}; + } + return sort keys %endpoints; +} diff --git a/challenge-285/paulo-custodio/perl/ch-2.pl b/challenge-285/paulo-custodio/perl/ch-2.pl new file mode 100644 index 0000000000..9bad9a6116 --- /dev/null +++ b/challenge-285/paulo-custodio/perl/ch-2.pl @@ -0,0 +1,63 @@ +#!/usr/bin/env perl + +# Challenge 285 +# +# Task 2: Making Change +# Submitted by: David Ferrone +# +# Compute the number of ways to make change for given amount in cents. By using +# the coins e.g. Penny, Nickel, Dime, Quarter and Half-dollar, in how many +# distinct ways can the total value equal to the given amount? Order of coin +# selection does not matter. +# +# A penny (P) is equal to 1 cent. +# A nickel (N) is equal to 5 cents. +# A dime (D) is equal to 10 cents. +# A quarter (Q) is equal to 25 cents. +# A half-dollar (HD) is equal to 50 cents. +# +# Example 1 +# +# Input: $amount = 9 +# Ouput: 2 +# +# 1: 9P +# 2: N + 4P +# +# Example 2 +# +# Input: $amount = 15 +# Ouput: 6 +# +# 1: D + 5P +# 2: D + N +# 3: 3N +# 4: 2N + 5P +# 5: N + 10P +# 6: 15P +# +# Example 3 +# +# Input: $amount = 100 +# Ouput: 292 + +use Modern::Perl; + +my @COINS = (50,25,10,5,1); + +my $amount = shift//0; +my $num_ways = compute_num_ways($amount, @COINS); +say $num_ways; + +sub compute_num_ways { + my($amount, @coins) = @_; + while (@coins>1 && $coins[0]>$amount) { + shift @coins; + } + return 1 if @coins==1; # return in cents + my $count; + for (my $v = 0; $v <= $amount; $v += $coins[0]) { + $count += compute_num_ways($amount-$v, @coins[1..$#coins]) + } + return $count; +} diff --git a/challenge-285/paulo-custodio/t/test-1.yaml b/challenge-285/paulo-custodio/t/test-1.yaml new file mode 100644 index 0000000000..836f002f22 --- /dev/null +++ b/challenge-285/paulo-custodio/t/test-1.yaml @@ -0,0 +1,10 @@ +- setup: + cleanup: + args: B C , D B , C A + input: + output: A +- setup: + cleanup: + args: A Z + input: + output: Z diff --git a/challenge-285/paulo-custodio/t/test-2.yaml b/challenge-285/paulo-custodio/t/test-2.yaml new file mode 100644 index 0000000000..70cfc904f2 --- /dev/null +++ b/challenge-285/paulo-custodio/t/test-2.yaml @@ -0,0 +1,15 @@ +- setup: + cleanup: + args: 9 + input: + output: 2 +- setup: + cleanup: + args: 15 + input: + output: 6 +- setup: + cleanup: + args: 100 + input: + output: 292 |
