aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-236/shimon-ben-avraham/raku/blog.txt1
-rwxr-xr-xchallenge-236/shimon-ben-avraham/raku/ch-1.raku78
-rwxr-xr-xchallenge-236/shimon-ben-avraham/raku/ch-2.raku2
3 files changed, 80 insertions, 1 deletions
diff --git a/challenge-236/shimon-ben-avraham/raku/blog.txt b/challenge-236/shimon-ben-avraham/raku/blog.txt
index f2d24d2d02..eefe78cb7f 100644
--- a/challenge-236/shimon-ben-avraham/raku/blog.txt
+++ b/challenge-236/shimon-ben-avraham/raku/blog.txt
@@ -1 +1,2 @@
+https://deoac.github.io/challenges/236/raku/task-1/index.html
https://deoac.github.io/challenges/236/raku/task-2/index.html
diff --git a/challenge-236/shimon-ben-avraham/raku/ch-1.raku b/challenge-236/shimon-ben-avraham/raku/ch-1.raku
new file mode 100755
index 0000000000..3e42366065
--- /dev/null
+++ b/challenge-236/shimon-ben-avraham/raku/ch-1.raku
@@ -0,0 +1,78 @@
+#! /usr/bin/env raku
+
+# Perl Weekly Challenge #236 Task 1
+# © 2023 Shimon Bollinger. All rights reserved.
+# Last modified: Sat 30 Sep 2023 11:41:30 PM EDT
+# Version 0.0.1
+
+# always use the latest version of Raku
+use v6.*;
+
+multi sub MAIN (
+ #| The bills to be used to make change (5, 10, 20)
+ *@input where all(@input) ~~ 5|10|20,
+ #| Show debug prints when True
+ Bool :v($verbose) = False
+ --> Str #Return 'true' if the bills can be used to make change
+ ) {
+
+ my Int %bills = (5 => 0, 10 => 0, 20 => 0);
+ my Str $retval = 'true';
+
+ for @input -> $bill {
+ %bills{$bill}++;
+
+ given $bill {
+ when 10 { %bills{5}-- }
+ when 20 {
+ %bills{5}--;
+ %bills{10} > 0
+ ?? (%bills{10} -= 1)
+ !! (%bills{5} -= 2);
+ } # end of when 20
+ } # end of given $bills
+
+ note "Received \$$bill, " ~
+ "have %bills{5} \$5s, %bills{10} \$10s, and %bills{20} \$20s " ~
+ "in the till" if $verbose; #
+ if %bills{5} < 0 {
+ $retval = 'false';
+ last;
+ } # end of if %bills{5} < 0
+ } # end of for @numbers -> $bill
+
+ say $retval;
+ return $retval;;
+} # end of multi MAIN (*@input where * == 5|10|20,
+
+# multi MAINs to catch invalid input
+multi sub MAIN (*@numbers where all(@numbers) ~~ Int,
+ Bool :v(:$verbose)) is hidden-from-USAGE {
+ note "The bills can only be 5, 10, or 20 dollars.";
+ exit 1;
+}
+
+multi sub MAIN(*@args,
+ Bool :v(:$verbose)) is hidden-from-USAGE {
+ note "Please provide a list of bills.";
+ exit 1;
+}
+
+#| Use the option '--test' to run the program with the three examples.
+multi MAIN (Bool :$test!) {
+ use Test;
+
+ my @tests = [
+ %{ got => MAIN(5, 5, 5, 10, 20),
+ op => 'eq', expected => 'true', desc => 'Example 1' },
+ %{ got => MAIN(5, 5, 10, 10, 20),
+ op => 'eq', expected => 'false', desc => 'Example 2' },
+ %{ got => MAIN(5, 5, 5, 20),
+ op => 'eq', expected => 'true', desc => 'Example 3' },
+ ];
+
+ plan +@tests;
+ for @tests {
+ cmp-ok .<got>, .<op>, .<expected>, .<desc>;
+ } # end of for @tests
+} # end of multi MAIN (:$test!) \ No newline at end of file
diff --git a/challenge-236/shimon-ben-avraham/raku/ch-2.raku b/challenge-236/shimon-ben-avraham/raku/ch-2.raku
index 8d57868fd0..fb3d14bc97 100755
--- a/challenge-236/shimon-ben-avraham/raku/ch-2.raku
+++ b/challenge-236/shimon-ben-avraham/raku/ch-2.raku
@@ -2,7 +2,7 @@
# Perl Weekly Challenge #236 Task 2
# © 2023 Shimon Bollinger. All rights reserved.
-# Last modified: Fri 29 Sep 2023 10:31:25 PM EDT
+# Last modified: Sat 30 Sep 2023 10:08:24 PM EDT
# Version 0.0.1
# always use the latest version of Raku