diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2023-11-18 22:58:26 +0000 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2023-11-18 22:58:26 +0000 |
| commit | dc0651a859d9824512ffbd2c84aba36b7392e84f (patch) | |
| tree | a8f3da7a5b92e7646a35a634e06457e5c327fafc /challenge-243 | |
| parent | c718d8efce844ad3beb24d9eff3b70d72d257330 (diff) | |
| download | perlweeklychallenge-club-dc0651a859d9824512ffbd2c84aba36b7392e84f.tar.gz perlweeklychallenge-club-dc0651a859d9824512ffbd2c84aba36b7392e84f.tar.bz2 perlweeklychallenge-club-dc0651a859d9824512ffbd2c84aba36b7392e84f.zip | |
- Added solutions by Laurent Rosenfeld.
- Added solutions by Packy Anderson.
- Added solutions by Lubos Kolouch.
- Added solutions by Jorg Sommrey.
- Added solutions by Paulo Custodio.
- Added solutions by Nelo Tovar.
- Added solutions by librasteve.
- Added solutions by Ian Rifkin.
Diffstat (limited to 'challenge-243')
| -rw-r--r-- | challenge-243/laurent-rosenfeld/blog1.txt | 1 | ||||
| -rw-r--r-- | challenge-243/laurent-rosenfeld/perl/ch-2.pl | 20 | ||||
| -rw-r--r-- | challenge-243/laurent-rosenfeld/raku/ch-2.raku | 13 |
3 files changed, 34 insertions, 0 deletions
diff --git a/challenge-243/laurent-rosenfeld/blog1.txt b/challenge-243/laurent-rosenfeld/blog1.txt new file mode 100644 index 0000000000..a685cc0b83 --- /dev/null +++ b/challenge-243/laurent-rosenfeld/blog1.txt @@ -0,0 +1 @@ +https://blogs.perl.org/users/laurent_r/2023/11/perl-weekly-challenge-243-floor-sum.html diff --git a/challenge-243/laurent-rosenfeld/perl/ch-2.pl b/challenge-243/laurent-rosenfeld/perl/ch-2.pl new file mode 100644 index 0000000000..f809e29071 --- /dev/null +++ b/challenge-243/laurent-rosenfeld/perl/ch-2.pl @@ -0,0 +1,20 @@ +use strict; +use warnings; +use feature 'say'; + +sub floor_sum { + my @in = @_; + my $end = $#in; + my $count = 0; + for my $i (0..$end) { + for my $j (0..$end) { + $count += int($in[$i] / $in[$j]) ; + } + } + return $count; +} + +for my $test ([<2 5 9>], [<4 9 3 2>], [<7 7 7 7 7 7 7>]) { + printf "%-15s => ", "@$test"; + say floor_sum @$test; +} diff --git a/challenge-243/laurent-rosenfeld/raku/ch-2.raku b/challenge-243/laurent-rosenfeld/raku/ch-2.raku new file mode 100644 index 0000000000..6c95bfcb1e --- /dev/null +++ b/challenge-243/laurent-rosenfeld/raku/ch-2.raku @@ -0,0 +1,13 @@ +sub floor-sum (@in) { + my $count = @in.elems; + for @in.combinations: 2 -> @pair { + $count += floor(@pair[0]/@pair[1]) + + floor(@pair[1]/@pair[0]); + } + return $count; +} + +for <2 5 9>, <4 9 3 2>, <7 7 7 7 7 7 7> -> @test { + printf "%-15s => ", "@test[]"; + say floor-sum @test; +} |
