From 84fd44fc915d5ea833e83d2a91114553c18e9438 Mon Sep 17 00:00:00 2001 From: Garrett Goebel Date: Tue, 8 Dec 2020 19:51:18 -0500 Subject: challenge-090 Task 2 Raku tweaks --- challenge-090/garrett-goebel/raku/ch-2.raku | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/challenge-090/garrett-goebel/raku/ch-2.raku b/challenge-090/garrett-goebel/raku/ch-2.raku index 35324621de..dede70ec31 100644 --- a/challenge-090/garrett-goebel/raku/ch-2.raku +++ b/challenge-090/garrett-goebel/raku/ch-2.raku @@ -1,17 +1,19 @@ #!/usr/bin/env raku -unit sub MAIN (Int $A where {$A > 0} = 14, Int $B where {$B > 0} = 12); +unit sub MAIN ( + Int $A is copy where $A > 0 = 14, + Int $B is copy where $B > 0 = 12 +); -my ($a, $b, $r) = ($A, $B, 0); # command line args are immutable +my Int $r = 0; +my $format = "%10d & %10d | product: %10d\n"; +$format.printf($A,$B, $r); -say "$a & $b"; - -if ($a > 1) { +if ($A > 1) { repeat { - $r += $b if $a mod 2; - say "{ $a div= 2 } & { $b *= 2 } | r: $r"; - } while $a > 1; + $r += $B if $A mod 2; + $format.printf($A div= 2, $B *= 2, $r); + } while $A > 1; } -$r += $b; - -say "r: $r"; +$r += $B; +~(' ' x 24 ~ "| product: %10d\n").printf($r); -- cgit