From d25dbda8b97eb3bfa860d8b3a356bddc90e47a94 Mon Sep 17 00:00:00 2001 From: Jason Messer Date: Mon, 3 Aug 2020 00:33:24 -0700 Subject: Weekly challenge #72 solutions for Jason Messer --- challenge-072/jason-messer/README | 1 + challenge-072/jason-messer/ch-1.p6 | 20 ++++++++++++++++++++ challenge-072/jason-messer/ch-2.p6 | 7 +++++++ 3 files changed, 28 insertions(+) create mode 100644 challenge-072/jason-messer/README create mode 100755 challenge-072/jason-messer/ch-1.p6 create mode 100755 challenge-072/jason-messer/ch-2.p6 diff --git a/challenge-072/jason-messer/README b/challenge-072/jason-messer/README new file mode 100644 index 0000000000..62394b16ea --- /dev/null +++ b/challenge-072/jason-messer/README @@ -0,0 +1 @@ +Solution by Jason Messer diff --git a/challenge-072/jason-messer/ch-1.p6 b/challenge-072/jason-messer/ch-1.p6 new file mode 100755 index 0000000000..d8d7d95629 --- /dev/null +++ b/challenge-072/jason-messer/ch-1.p6 @@ -0,0 +1,20 @@ +#! /usr/bin/env rakudo +sub count-trailing-zeros(Int $n) { + my $running = $n; + my Int $count = 0; + while ($running > 0) { + if ($running %% 10) { + $running /= 10; + ++$count; + } else { + last; + } + } + return $count; +} + +my $fac := lazy 1, { $^a * ++$ } ... *; + +say count-trailing-zeros($fac[10]); +say count-trailing-zeros($fac[7]); +say count-trailing-zeros($fac[4]); diff --git a/challenge-072/jason-messer/ch-2.p6 b/challenge-072/jason-messer/ch-2.p6 new file mode 100755 index 0000000000..27ab3156ec --- /dev/null +++ b/challenge-072/jason-messer/ch-2.p6 @@ -0,0 +1,7 @@ +#! /usr/bin/env rakudo +sub MAIN($fname, $first_line, $last_line) { + my $fh = open $fname, :chomp(False) or die($fh); + $fh.lines($first_line - 1).eager; + my $n = $last_line - ($first_line - 1); + for ($fh.lines($n)) { .print } +} -- cgit