diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-07-02 12:53:17 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-02 12:53:17 +0100 |
| commit | 84d075e22b12bb04aa4ff46a0adcb0b8e076f316 (patch) | |
| tree | 786f8857623cdd83f752ae7bd6190d7df21d7b5c | |
| parent | 3498ffc39b9f1fc347236d59a3d4d9028c365da2 (diff) | |
| parent | e05f3d419cf1887cbf605861d0d5ce39eb8c522d (diff) | |
| download | perlweeklychallenge-club-84d075e22b12bb04aa4ff46a0adcb0b8e076f316.tar.gz perlweeklychallenge-club-84d075e22b12bb04aa4ff46a0adcb0b8e076f316.tar.bz2 perlweeklychallenge-club-84d075e22b12bb04aa4ff46a0adcb0b8e076f316.zip | |
Merge pull request #10363 from jmaslak/jmaslak-challenge-276
Joelle Maslak's Week 276 solutions
| -rwxr-xr-x | challenge-276/joelle-maslak/perl/ch-1.pl | 23 | ||||
| -rwxr-xr-x | challenge-276/joelle-maslak/perl/ch-2.pl | 26 | ||||
| -rwxr-xr-x | challenge-276/joelle-maslak/raku/ch-1.raku | 10 | ||||
| -rwxr-xr-x | challenge-276/joelle-maslak/raku/ch-2.raku | 11 | ||||
| -rwxr-xr-x | challenge-276/joelle-maslak/test-1.sh | 27 | ||||
| -rwxr-xr-x | challenge-276/joelle-maslak/test-2.sh | 26 |
6 files changed, 123 insertions, 0 deletions
diff --git a/challenge-276/joelle-maslak/perl/ch-1.pl b/challenge-276/joelle-maslak/perl/ch-1.pl new file mode 100755 index 0000000000..112a898d4e --- /dev/null +++ b/challenge-276/joelle-maslak/perl/ch-1.pl @@ -0,0 +1,23 @@ +#!/usr/bin/perl + +use v5.34; +use strict; +use warnings; + +MAIN: { + my $hourstr = join " ", @ARGV; + $hourstr =~ s/[(),]/ /g; + $hourstr =~ s/^\s*(.*)\s*$/$1/g; + my (@hours) = split /\s+/, $hourstr; + + my %pairs; + for (my $i=0; $i+1<scalar(@hours); $i++) { + for (my $j=$i+1; $j<scalar(@hours); $j++) { + if (!(($hours[$i] + $hours[$j]) % 24)) { + $pairs{join ":", sort($hours[$i], $hours[$j])} = 1; + } + } + } + + say scalar(keys(%pairs)); +}
\ No newline at end of file diff --git a/challenge-276/joelle-maslak/perl/ch-2.pl b/challenge-276/joelle-maslak/perl/ch-2.pl new file mode 100755 index 0000000000..06b8c9078a --- /dev/null +++ b/challenge-276/joelle-maslak/perl/ch-2.pl @@ -0,0 +1,26 @@ +#!/usr/bin/perl + +use JTM::Boilerplate 'script'; +use List::Util qw(max); + +MAIN: { + my $numstr = join " ", @ARGV; + $numstr =~ s/[(),]/ /g; + $numstr =~ s/^\s*(.*)\s*$/$1/g; + my (@nums) = split /\s+/, $numstr; + + my %counts; + for my $v (@nums) { + $counts{$v}++; + } + + my %freqs; + for my $k (keys %counts) { + my $v = $counts{$k}; + $freqs{$v} //= []; + push $freqs{$v}->@*, $k; + } + + my $max = max keys %freqs; + say $max*scalar($freqs{$max}->@*); +} diff --git a/challenge-276/joelle-maslak/raku/ch-1.raku b/challenge-276/joelle-maslak/raku/ch-1.raku new file mode 100755 index 0000000000..4ca351de20 --- /dev/null +++ b/challenge-276/joelle-maslak/raku/ch-1.raku @@ -0,0 +1,10 @@ +#!/usr/bin/env raku +use v6.d; + +sub MAIN(Str:D $numberstr is copy) { + $numberstr ~~ s:g/<[(),]>/ /; + $numberstr ~~ s/^ \s+ (.*) \s+ $/$0/; + my @hours = $numberstr.split(/\s+/); + + say @hours.combinations(2).grep(*.sum %% 24).elems; +}
\ No newline at end of file diff --git a/challenge-276/joelle-maslak/raku/ch-2.raku b/challenge-276/joelle-maslak/raku/ch-2.raku new file mode 100755 index 0000000000..f0df911045 --- /dev/null +++ b/challenge-276/joelle-maslak/raku/ch-2.raku @@ -0,0 +1,11 @@ +#!/usr/bin/env raku +use v6.d; + +sub MAIN(Str:D $numberstr is copy) { + $numberstr ~~ s:g/<[(),]>/ /; + $numberstr ~~ s/^ \s+ (.*) \s+ $/$0/; + my $nums = Bag.new($numberstr.split(/\s+/)ยป.Int); + + my $max = $nums.values.max; + say $max * $nums.grep(*.value == $max).elems; +} diff --git a/challenge-276/joelle-maslak/test-1.sh b/challenge-276/joelle-maslak/test-1.sh new file mode 100755 index 0000000000..fcfc6ce6e0 --- /dev/null +++ b/challenge-276/joelle-maslak/test-1.sh @@ -0,0 +1,27 @@ +#!/bin/bash +set -e + +test_it() { + echo -n $1 "'$2'" ... + OUT=$($1 "$2") + if [ "$OUT" == "$3" ] ; then + echo "ok" + else + echo "INCORRECT ($OUT)" + fi +} + +test_combo() { + test_it "$1" "(12, 12, 30, 24, 24)" 2 + test_it "$1" "(72, 48, 24, 5)" 3 + test_it "$1" "(12, 18, 24)" 0 +} + +do_it() { + test_combo "perl perl/ch-1.pl" + test_combo "raku raku/ch-1.raku" +} + +do_it "$@" + + diff --git a/challenge-276/joelle-maslak/test-2.sh b/challenge-276/joelle-maslak/test-2.sh new file mode 100755 index 0000000000..1872762c17 --- /dev/null +++ b/challenge-276/joelle-maslak/test-2.sh @@ -0,0 +1,26 @@ +#!/bin/bash +set -e + +test_it() { + echo -n $1 $2 ... + OUT=$($1 "$2") + if [ "$OUT" == "$3" ] ; then + echo "ok" + else + echo "INCORRECT ($OUT)" + fi +} + +test_combo() { + test_it "$1" "(1, 2, 2, 4, 1, 5)" 4 + test_it "$1" "(1, 2, 3, 4, 5)" 5 +} + +do_it() { + test_combo "perl perl/ch-2.pl" + test_combo "raku raku/ch-2.raku" +} + +do_it "$@" + + |
