aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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');