From 92bca8acd9f04554d20db218ac088748592d1f43 Mon Sep 17 00:00:00 2001 From: Simon Proctor Date: Thu, 27 Aug 2020 10:15:18 +0100 Subject: Added a pretty print option --- challenge-075/simon-proctor/raku/ch-1.raku | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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; -- cgit