aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-08-17 09:06:38 +0100
committerGitHub <noreply@github.com>2021-08-17 09:06:38 +0100
commit98fd79b532d89799663b9dd0183581689e75fca2 (patch)
tree55ac33953df14bd88b2b970f7f9888b288f10846
parent0819af3198a49489cc0b96e1e3469f998db47ffe (diff)
parentf9c2901f6f712a83492e95b35e68c8becbc9e4d5 (diff)
downloadperlweeklychallenge-club-98fd79b532d89799663b9dd0183581689e75fca2.tar.gz
perlweeklychallenge-club-98fd79b532d89799663b9dd0183581689e75fca2.tar.bz2
perlweeklychallenge-club-98fd79b532d89799663b9dd0183581689e75fca2.zip
Merge pull request #4735 from ash/ash-126
use given/when
-rw-r--r--challenge-126/ash/raku/ch-1.raku18
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;