diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2021-12-08 19:26:22 +0000 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2021-12-08 19:26:22 +0000 |
| commit | 9291144cd854b66ef16328abec4ea884ed1c9eb5 (patch) | |
| tree | 7f487844d9b7fcf0f7ea48554fe6d62b8d959315 /challenge-142 | |
| parent | 165b62d8a68fb2f104c98aaf7a3137f762e52769 (diff) | |
| download | perlweeklychallenge-club-9291144cd854b66ef16328abec4ea884ed1c9eb5.tar.gz perlweeklychallenge-club-9291144cd854b66ef16328abec4ea884ed1c9eb5.tar.bz2 perlweeklychallenge-club-9291144cd854b66ef16328abec4ea884ed1c9eb5.zip | |
- Added solutions by Laurent Rosenfeld.
Diffstat (limited to 'challenge-142')
| -rw-r--r-- | challenge-142/laurent-rosenfeld/blog.txt | 1 | ||||
| -rw-r--r-- | challenge-142/laurent-rosenfeld/perl/ch-1.pl | 14 | ||||
| -rw-r--r-- | challenge-142/laurent-rosenfeld/perl/ch-2.pl | 10 | ||||
| -rw-r--r-- | challenge-142/laurent-rosenfeld/raku/ch-1.raku | 12 | ||||
| -rw-r--r-- | challenge-142/laurent-rosenfeld/raku/ch-2.raku | 3 |
5 files changed, 40 insertions, 0 deletions
diff --git a/challenge-142/laurent-rosenfeld/blog.txt b/challenge-142/laurent-rosenfeld/blog.txt new file mode 100644 index 0000000000..74cd4cc0af --- /dev/null +++ b/challenge-142/laurent-rosenfeld/blog.txt @@ -0,0 +1 @@ +http://blogs.perl.org/users/laurent_r/2021/12/perl-weekly-challenge-142-divisor-last-digit-and-sleep-sort.html diff --git a/challenge-142/laurent-rosenfeld/perl/ch-1.pl b/challenge-142/laurent-rosenfeld/perl/ch-1.pl new file mode 100644 index 0000000000..8256b861ab --- /dev/null +++ b/challenge-142/laurent-rosenfeld/perl/ch-1.pl @@ -0,0 +1,14 @@ +use strict; +use warnings; +use feature "say"; + +sub count_divisors { + my ($m, $n) = @_; + my @divisors = grep {$m % $_ == 0} 1..$m; + my $last_digit = substr $n, -1, 1; + my @eligible_divisors = grep { $last_digit == substr $_, -1, 1 } @divisors; + return scalar @eligible_divisors; +} +for ([24, 34], [24, 12], [30, 45]) { + say "@$_ -> ", count_divisors $_->[0], $_->[1]; +} diff --git a/challenge-142/laurent-rosenfeld/perl/ch-2.pl b/challenge-142/laurent-rosenfeld/perl/ch-2.pl new file mode 100644 index 0000000000..dbba9c1830 --- /dev/null +++ b/challenge-142/laurent-rosenfeld/perl/ch-2.pl @@ -0,0 +1,10 @@ +use strict; +use warnings; +use feature "say"; + +while ($_ = shift and @ARGV >= 1) { + last unless fork; +} +sleep $_; +say; +wait; diff --git a/challenge-142/laurent-rosenfeld/raku/ch-1.raku b/challenge-142/laurent-rosenfeld/raku/ch-1.raku new file mode 100644 index 0000000000..54f69b3d81 --- /dev/null +++ b/challenge-142/laurent-rosenfeld/raku/ch-1.raku @@ -0,0 +1,12 @@ +use v6; + +sub count_divisors (UInt $m, UInt $n) { + my @divisors = grep {$m %% $_}, 1..$m; + my $last-digit = substr $n, *-1; + my @eligible-divisors = grep { $last-digit == substr $_, *-1 }, @divisors; + return @eligible-divisors.elems; +} + +for (24, 34), (24, 12), (30, 45) { + say "$_ -> ", count_divisors $_[0], $_[1]; +} diff --git a/challenge-142/laurent-rosenfeld/raku/ch-2.raku b/challenge-142/laurent-rosenfeld/raku/ch-2.raku new file mode 100644 index 0000000000..a119116b83 --- /dev/null +++ b/challenge-142/laurent-rosenfeld/raku/ch-2.raku @@ -0,0 +1,3 @@ +use v6; + +await <6 8 1 12 2 14 5 2 1 0>.map: { start {sleep $_/2; .say} }; |
