From e05f3d419cf1887cbf605861d0d5ce39eb8c522d Mon Sep 17 00:00:00 2001 From: Joelle Maslak Date: Mon, 1 Jul 2024 21:47:50 -0600 Subject: Joelle Maslak's Week 276 solutions --- challenge-276/joelle-maslak/perl/ch-1.pl | 23 +++++++++++++++++++++++ challenge-276/joelle-maslak/perl/ch-2.pl | 26 ++++++++++++++++++++++++++ challenge-276/joelle-maslak/raku/ch-1.raku | 10 ++++++++++ challenge-276/joelle-maslak/raku/ch-2.raku | 11 +++++++++++ challenge-276/joelle-maslak/test-1.sh | 27 +++++++++++++++++++++++++++ challenge-276/joelle-maslak/test-2.sh | 26 ++++++++++++++++++++++++++ 6 files changed, 123 insertions(+) create mode 100755 challenge-276/joelle-maslak/perl/ch-1.pl create mode 100755 challenge-276/joelle-maslak/perl/ch-2.pl create mode 100755 challenge-276/joelle-maslak/raku/ch-1.raku create mode 100755 challenge-276/joelle-maslak/raku/ch-2.raku create mode 100755 challenge-276/joelle-maslak/test-1.sh create mode 100755 challenge-276/joelle-maslak/test-2.sh 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@*, $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 "$@" + + -- cgit