aboutsummaryrefslogtreecommitdiff
path: root/challenge-276
diff options
context:
space:
mode:
authorrir <rirans@comcast.net>2024-07-07 17:11:35 -0400
committerrir <rirans@comcast.net>2024-07-07 17:11:35 -0400
commit9172a809f4ddd37f10f297009ec3034ed916400a (patch)
treec802de188ddb528c7aea52fd1f7ed21f7ee8b574 /challenge-276
parent757bec959ede495aea7053ebae49541691b14466 (diff)
downloadperlweeklychallenge-club-9172a809f4ddd37f10f297009ec3034ed916400a.tar.gz
perlweeklychallenge-club-9172a809f4ddd37f10f297009ec3034ed916400a.tar.bz2
perlweeklychallenge-club-9172a809f4ddd37f10f297009ec3034ed916400a.zip
276
Diffstat (limited to 'challenge-276')
-rw-r--r--challenge-276/0rir/raku/ch-1.raku57
-rw-r--r--challenge-276/0rir/raku/ch-2.raku63
2 files changed, 120 insertions, 0 deletions
diff --git a/challenge-276/0rir/raku/ch-1.raku b/challenge-276/0rir/raku/ch-1.raku
new file mode 100644
index 0000000000..527ac11e6f
--- /dev/null
+++ b/challenge-276/0rir/raku/ch-1.raku
@@ -0,0 +1,57 @@
+#!/usr/bin/env raku
+# :vim ft=raku sw=4 expandtab # 🦋 ∅∪∩∋∈∉⊆ ≡ ≢ «␤ » ∴
+use v6.d;
+use Test;
+
+=begin comment
+276-1  Complete Day Submitted by: Mohammad Sajid Anwar
+
+You are given an array of integers, @hours. Write a script to return
+the number of pairs that forms a complete day. A complete day is defined
+as a time duration that is an exact multiple of 24 hours.
+
+Example 1
+Input: @hours = (12, 12, 30, 24, 24)
+Output: 2
+
+Pair 1: (12, 12)
+Pair 2: (24, 24)
+Example 2
+Input: @hours = (72, 48, 24, 5)
+Output: 3
+
+Pair 1: (72, 48)
+Pair 2: (72, 24)
+Pair 3: (48, 24)
+Example 3
+Input: @hours = (12, 18, 24)
+Output: 0
+=end comment
+
+my @Test =
+ # exp in
+ Int, (),
+ 0, (1,),
+ 2, (12, 12, 24, 24, 30),
+ 3, (72, 48, 24, 5),
+ 0, ( 72, 5, 3),
+ 0, ( 12, 24, 18),
+ 6, (12, 12, 12, 12, 24, 7,4,1),
+ 9, (2, 2, 2, 2, 0, 24, 24, 7,4,1),
+;
+plan @Test ÷ 2;
+
+multi task( @a where * !~~ Empty --> Int) {
+ @a.classify( * % 24 ).values.map( { $_.elems × $_.end div 2}).sum;
+}
+multi task( @a --> Int) { Int }
+
+for @Test -> $exp, @in {
+ is task(@in), $exp, ($exp // "Int") ~ " <- @in.raku()";
+}
+
+done-testing;
+
+my @hour = (12, 12, 12, 12, 36, 60, 0, 24, 24, 48, 7, 4, 1);
+say "\nInput: \@hour = @hour[]\nOutput: &task(@hour)";
+
diff --git a/challenge-276/0rir/raku/ch-2.raku b/challenge-276/0rir/raku/ch-2.raku
new file mode 100644
index 0000000000..1d3204971c
--- /dev/null
+++ b/challenge-276/0rir/raku/ch-2.raku
@@ -0,0 +1,63 @@
+#!/usr/bin/env raku
+# :vim ft=raku sw=4 expandtab # 🦋 ∅∪∩∋∈∉⊆ ≡ ≢ «␤ » ∴
+use v6.d;
+use Test;
+
+=begin comment
+276-2 Maximum Frequency Submitted by: Mohammad Sajid Anwar
+
+You are given an array of positive integers, @ints. Write a script to
+return the total number of elements in the given array which have the
+highest frequency.
+
+Example 1
+Input: @ints = (1, 2, 2, 4, 1, 5)
+Ouput: 4
+
+The maximum frequency is 2.
+The elements 1 and 2 has the maximum frequency.
+Example 2
+Input: @ints = (1, 2, 3, 4, 5)
+Ouput: 5
+
+The maximum frequency is 1.
+The elements 1, 2, 3, 4 and 5 has the maximum frequency.
+
+=end comment
+
+my @Test =
+ # exp in
+ Int, List,
+ Int, Array,
+# Int, Seq,
+ 3, (1…3),
+ 0, (),
+ 0, [],
+ 4, (1, 2, 2, 4, 1, 5),
+ 5, (1, 2, 3, 4, 5),
+ 10, (1, 2, 3, 4, 5, 6, 2, 3, 4, 5, 6),
+;
+
+plan @Test ÷ 2;
+
+constant \MAX-RET-LIST = $*RAKU.compiler.version.Str ge "2023.08";
+
+#multi task( @a where { ! .defined and .isa( Seq) } ) { Int }
+multi task( @a where { ! .defined and .isa( List)} ) { Int }
+multi task( @a) {
+
+ if not MAX-RET-LIST { return sum @a.Bag.max( :v); }
+
+ my @v =@a.Bag.values».Int;
+ return sum grep ( * == @v.max ), @v;
+}
+
+for @Test -> $exp, @in {
+ is task(@in), $exp, !$exp.defined ?? '(Int)' !! " $exp <- @in.raku()";
+}
+
+done-testing;
+
+my @int = 1, 2, 3, 4, 2, 3, 4, 3, 4, 3, 4, 5;
+say "\nInput: @ints = @int.raku()\nOutput: ", task( @int);
+