diff options
| author | Andrew Shitov <andy@shitov.ru> | 2021-08-17 09:36:59 +0200 |
|---|---|---|
| committer | Andrew Shitov <andy@shitov.ru> | 2021-08-17 09:36:59 +0200 |
| commit | f9c2901f6f712a83492e95b35e68c8becbc9e4d5 (patch) | |
| tree | 6d1bbcd97a1cab615efb379e76a628e168686aac | |
| parent | b0257db0d734f63a09779995ebedf01f7c9b2ebe (diff) | |
| download | perlweeklychallenge-club-f9c2901f6f712a83492e95b35e68c8becbc9e4d5.tar.gz perlweeklychallenge-club-f9c2901f6f712a83492e95b35e68c8becbc9e4d5.tar.bz2 perlweeklychallenge-club-f9c2901f6f712a83492e95b35e68c8becbc9e4d5.zip | |
use given/when
| -rw-r--r-- | challenge-126/ash/raku/ch-1.raku | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/challenge-126/ash/raku/ch-1.raku b/challenge-126/ash/raku/ch-1.raku index d1c42c4796..08d68052e4 100644 --- a/challenge-126/ash/raku/ch-1.raku +++ b/challenge-126/ash/raku/ch-1.raku @@ -1,18 +1,18 @@ sub count($n) { my @items = (2..$n).grep: * !~~ /1/; - if @items { - if @items.elems == 1 { + given @items.elems { + when 0 { + say "There are no numbers up to $n that contain no digit 1."; + } + when 1 { say "There is 1 number between 1 and $n that doesn't contain digit 1."; } - else { + default { say "There are {+@items} numbers between 1 and $n that don't contain digit 1."; } - - say @items.join(', ') ~ '.'; - } - else { - say "There are no numbers between 1 and $n that contain no digit 1."; } + + say @items.join(', ') ~ '.' if @items; } -.&count for 5, 15, 25; +.&count for 1, 2, 5, 15, 25; |
