aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvery Adams <oldtechaa@gmail.com>2023-09-30 23:43:30 +1300
committerAvery Adams <oldtechaa@gmail.com>2023-09-30 23:43:30 +1300
commit4d453267995fe48581e7ac1dcdc8dbf91cb423bf (patch)
treef134ecee526e0b9297add4b2a8610bc70e78d79c
parent200e728ec7b29b6f1807ed966264407834eb9f92 (diff)
downloadperlweeklychallenge-club-4d453267995fe48581e7ac1dcdc8dbf91cb423bf.tar.gz
perlweeklychallenge-club-4d453267995fe48581e7ac1dcdc8dbf91cb423bf.tar.bz2
perlweeklychallenge-club-4d453267995fe48581e7ac1dcdc8dbf91cb423bf.zip
Add solutions for Avery Adams for 236
-rw-r--r--challenge-236/avery-adams/blogs.txt2
-rw-r--r--challenge-236/avery-adams/perl/ch-1.pl31
2 files changed, 33 insertions, 0 deletions
diff --git a/challenge-236/avery-adams/blogs.txt b/challenge-236/avery-adams/blogs.txt
new file mode 100644
index 0000000000..799201262d
--- /dev/null
+++ b/challenge-236/avery-adams/blogs.txt
@@ -0,0 +1,2 @@
+https://dev.to/oldtechaa/perl-weekly-challenge-236-lemonade-stand-50p5
+https://blogs.perl.org/users/oldtechaa/2023/09/perl-weekly-challenge-236---lemonade-stand.html
diff --git a/challenge-236/avery-adams/perl/ch-1.pl b/challenge-236/avery-adams/perl/ch-1.pl
new file mode 100644
index 0000000000..55ce240fe5
--- /dev/null
+++ b/challenge-236/avery-adams/perl/ch-1.pl
@@ -0,0 +1,31 @@
+#!/usr/bin/perl
+use v5.36;
+use List::Util 'any';
+
+my %till;
+my $failure;
+foreach my $bill (@ARGV) {
+ if(!any {$bill == $_} (5, 10, 20)) {
+ say('At least one bill provided is not $5, $10, or $20.') and exit;
+ }
+ $till{$bill}++;
+ if($bill == 20) {
+ if($till{10} and $till{5}) {
+ $till{10}--;
+ $till{5}--;
+ } elsif($till{5} >= 3) {
+ $till{5} -= 3;
+ } else {
+ $failure = 'false';
+ last;
+ }
+ } elsif($bill == 10) {
+ if($till{5}) {
+ $till{5}--;
+ } else {
+ $failure = 'false';
+ last;
+ }
+ }
+}
+say(defined($failure) ? $failure : 'true');