diff options
| author | Simon Proctor <simon.proctor@zoopla.co.uk> | 2020-08-27 10:15:18 +0100 |
|---|---|---|
| committer | Simon Proctor <simon.proctor@zoopla.co.uk> | 2020-08-27 10:15:18 +0100 |
| commit | 92bca8acd9f04554d20db218ac088748592d1f43 (patch) | |
| tree | 88413a53eb7d4986776880543bd5af8535089788 | |
| parent | 2e8749976783f09a56c3249c7034cd157431cc0f (diff) | |
| download | perlweeklychallenge-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.raku | 11 |
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; |
