From f9c2901f6f712a83492e95b35e68c8becbc9e4d5 Mon Sep 17 00:00:00 2001 From: Andrew Shitov Date: Tue, 17 Aug 2021 09:36:59 +0200 Subject: use given/when --- challenge-126/ash/raku/ch-1.raku | 18 +++++++++--------- 1 file 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; -- cgit