aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Proctor <simon.proctor@zoopla.co.uk>2020-08-27 10:15:18 +0100
committerSimon Proctor <simon.proctor@zoopla.co.uk>2020-08-27 10:15:18 +0100
commit92bca8acd9f04554d20db218ac088748592d1f43 (patch)
tree88413a53eb7d4986776880543bd5af8535089788
parent2e8749976783f09a56c3249c7034cd157431cc0f (diff)
downloadperlweeklychallenge-club-92bca8acd9f04554d20db218ac088748592d1f43.tar.gz
perlweeklychallenge-club-92bca8acd9f04554d20db218ac088748592d1f43.tar.bz2
perlweeklychallenge-club-92bca8acd9f04554d20db218ac088748592d1f43.zip
Added a pretty print option
-rw-r--r--challenge-075/simon-proctor/raku/ch-1.raku11
1 files changed, 10 insertions, 1 deletions
diff --git a/challenge-075/simon-proctor/raku/ch-1.raku b/challenge-075/simon-proctor/raku/ch-1.raku
index f907ee7190..a1ba1a7ca1 100644
--- a/challenge-075/simon-proctor/raku/ch-1.raku
+++ b/challenge-075/simon-proctor/raku/ch-1.raku
@@ -9,10 +9,19 @@ sub MAIN (
UInt $amount where * > 0, #= Amount to make change of
*@coins where { .all ~~ Int && .all > 0 }, #= Valid coins
Bool :v(:$verbose) = False, #= Print the complete list of combinations
+ Str :p(:$pretty) = "", #= If in verbose mode and set to a value uses this as the coin type (eg 'p' or 'c')
) {
my @change = make-change( $amount, @coins );
say @change.elems;
- if $verbose { .join(", ").say for @change }
+ if $verbose {
+ if $pretty {
+ for @change -> @list {
+ @list.Bag.pairs.sort( { $^b.key cmp $^a.key } ).map( { "{$_.value} x {$_.key}{$pretty}" } ).join( ", ").say;
+ }
+ } else {
+ .join(", ").say for @change;
+ }
+ }
}
my %change_cache;