diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2023-11-15 20:59:23 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-15 20:59:23 +0000 |
| commit | 2bf36663688c70da5d1a88a526564650cbac6969 (patch) | |
| tree | 7bed2b3cd43f5dcb4a2afccfc09a53f5b9ca8ab7 /challenge-243 | |
| parent | 6a15479b2038c544a6eba8bb3c82df2eb4cb0ba5 (diff) | |
| parent | 6a48cbd08775fa750199d0c9fad6476b6e9c46ff (diff) | |
| download | perlweeklychallenge-club-2bf36663688c70da5d1a88a526564650cbac6969.tar.gz perlweeklychallenge-club-2bf36663688c70da5d1a88a526564650cbac6969.tar.bz2 perlweeklychallenge-club-2bf36663688c70da5d1a88a526564650cbac6969.zip | |
Merge pull request #9064 from jacoby/master
243 DAJ
Diffstat (limited to 'challenge-243')
| -rw-r--r-- | challenge-243/dave-jacoby/blog.txt | 1 | ||||
| -rw-r--r-- | challenge-243/dave-jacoby/perl/ch-1.pl | 33 | ||||
| -rw-r--r-- | challenge-243/dave-jacoby/perl/ch-2.pl | 34 |
3 files changed, 68 insertions, 0 deletions
diff --git a/challenge-243/dave-jacoby/blog.txt b/challenge-243/dave-jacoby/blog.txt new file mode 100644 index 0000000000..7321682ccb --- /dev/null +++ b/challenge-243/dave-jacoby/blog.txt @@ -0,0 +1 @@ +https://jacoby.github.io/2023/11/14/walking-the-floor-over-you-weekly-challenge-243.html diff --git a/challenge-243/dave-jacoby/perl/ch-1.pl b/challenge-243/dave-jacoby/perl/ch-1.pl new file mode 100644 index 0000000000..a54edcdb8d --- /dev/null +++ b/challenge-243/dave-jacoby/perl/ch-1.pl @@ -0,0 +1,33 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use experimental qw{ say postderef signatures state }; + +use List::Compare; + +my @examples = ( + + [ 1, 3, 2, 3, 1 ], + [ 2, 4, 3, 5, 1 ], +); +for my $e (@examples) { + my $output = reverse_pairs( $e->@* ); + my $input = join ', ', $e->@*; + say <<~"END"; + Input: \@input = ($input) + Output: $output + END +} + +sub reverse_pairs (@input) { + my $output = 0; + for my $i ( 0 .. -1 + scalar @input ) { + my $ii = $input[$i]; + for my $j ( $i + 1 .. -1 + scalar @input ) { + my $jj = $input[$j]; + $output++ if $ii > $jj * 2; + } + } + return $output; +} diff --git a/challenge-243/dave-jacoby/perl/ch-2.pl b/challenge-243/dave-jacoby/perl/ch-2.pl new file mode 100644 index 0000000000..764d223f86 --- /dev/null +++ b/challenge-243/dave-jacoby/perl/ch-2.pl @@ -0,0 +1,34 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use experimental qw{ say postderef signatures state }; + +my @examples = ( + + [ 2, 5, 9 ], + [ 7, 7, 7, 7, 7, 7, 7 ], +); + +for my $e (@examples) { + my $input = join ', ', $e->@*; + my $output = floor_sum( $e->@* ); + + say <<~"END"; + Input: \$input = ($input) + Output: $output + END +} + +sub floor_sum (@input) { + my $output = 0; + for my $i ( 0 .. -1 + scalar @input ) { + my $ii = $input[$i]; + for my $j ( 0 .. -1 + scalar @input ) { + my $jj = $input[$j]; + my $floor = int( $ii / $jj ); + $output += $floor; + } + } + return $output; +} |
