aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-07-28 21:34:38 +0100
committerGitHub <noreply@github.com>2024-07-28 21:34:38 +0100
commit6424dd34c55ecaa347e496ee26b4ec4f45b4b992 (patch)
tree1dbeb4041f1dd79f4b18c9bd1a966113356e4ad1
parenta7757ce18078fa945454e0184f8827d685985b70 (diff)
parenta7048d3bd0623c7e4af8b656833c3e3e3e21414b (diff)
downloadperlweeklychallenge-club-6424dd34c55ecaa347e496ee26b4ec4f45b4b992.tar.gz
perlweeklychallenge-club-6424dd34c55ecaa347e496ee26b4ec4f45b4b992.tar.bz2
perlweeklychallenge-club-6424dd34c55ecaa347e496ee26b4ec4f45b4b992.zip
Merge pull request #10502 from BarrOff/barroff-279
feat: add solutions for challenge 279 from BarrOff
-rw-r--r--challenge-279/barroff/julia/ch-1.jl14
-rw-r--r--challenge-279/barroff/julia/ch-2.jl14
-rw-r--r--challenge-279/barroff/raku/ch-1.p626
-rw-r--r--challenge-279/barroff/raku/ch-2.p622
4 files changed, 76 insertions, 0 deletions
diff --git a/challenge-279/barroff/julia/ch-1.jl b/challenge-279/barroff/julia/ch-1.jl
new file mode 100644
index 0000000000..a5e8666483
--- /dev/null
+++ b/challenge-279/barroff/julia/ch-1.jl
@@ -0,0 +1,14 @@
+#!/usr/bin/env julia
+
+using Test: @test, @testset
+
+function sort_letters(letters::Vector{Char}, weights::Vector{Int})::String
+ ldict = Dict([z[2] => z[1] for z in zip(letters, weights)])
+ return join([ldict[i] for i = 1:length(weights)])
+end
+
+@testset "sort letters" begin
+ @test sort_letters(['R', 'E', 'P', 'L'], [3, 2, 1, 4]) == "PERL"
+ @test sort_letters(['A', 'U', 'R', 'K'], [2, 4, 1, 3]) == "RAKU"
+ @test sort_letters(['O', 'H', 'Y', 'N', 'P', 'T'], [5, 4, 2, 6, 1, 3]) == "PYTHON"
+end
diff --git a/challenge-279/barroff/julia/ch-2.jl b/challenge-279/barroff/julia/ch-2.jl
new file mode 100644
index 0000000000..2e0d370b77
--- /dev/null
+++ b/challenge-279/barroff/julia/ch-2.jl
@@ -0,0 +1,14 @@
+#!/usr/bin/env julia
+
+using Test: @test, @testset
+
+function split_string(str::AbstractString)::Bool
+ vowels = Set(['a', 'e', 'i', 'o', 'u'])
+ count(x -> x in vowels, collect(str)) % 2 == 0
+end
+
+@testset "split string" begin
+ @test split_string("perl") == false
+ @test split_string("book") == true
+ @test split_string("good morning") == true
+end
diff --git a/challenge-279/barroff/raku/ch-1.p6 b/challenge-279/barroff/raku/ch-1.p6
new file mode 100644
index 0000000000..0bc0216b39
--- /dev/null
+++ b/challenge-279/barroff/raku/ch-1.p6
@@ -0,0 +1,26 @@
+#!/usr/bin/env raku
+
+use v6.d;
+
+sub sort-letters(@letters, @weights where @letters.elems == @weights.elems --> Str) {
+ my %ldict = @weights Z=> @letters;
+ %ldict{1..@weights.elems}.join;
+}
+
+#| Run test cases
+multi sub MAIN('test') {
+ use Test;
+ plan 3;
+
+ is sort-letters(('R', 'E', 'P', 'L'), (3, 2, 1, 4)), 'PERL',
+ 'works for ("R", "E", "P", "L") and (3, 2, 1, 4)';
+ is sort-letters(('A', 'U', 'R', 'K'), (2, 4, 1, 3)), 'RAKU',
+ 'works for ("A", "U", "R", "K") and (2, 4, 1, 3)';
+ is sort-letters(('O', 'H', 'Y', 'N', 'P', 'T'), (5, 4, 2, 6, 1, 3)), 'PYTHON',
+ 'works for ("O", "H", "Y", "N", "P", "T") and (5, 4, 2, 6, 1, 3)';
+}
+
+#| Take user provided letters and weights like R E P L 3 2 1 4
+multi sub MAIN(Str @letters, Int @weights) {
+ say sort-letters(@letters, @weights);
+}
diff --git a/challenge-279/barroff/raku/ch-2.p6 b/challenge-279/barroff/raku/ch-2.p6
new file mode 100644
index 0000000000..896dd66d3b
--- /dev/null
+++ b/challenge-279/barroff/raku/ch-2.p6
@@ -0,0 +1,22 @@
+#!/usr/bin/env raku
+
+use v6.d;
+
+sub split-string(Str $str--> Bool) {
+ grep({ /<[aeiou]>/ }, $str.comb).elems mod 2 == 0;
+}
+
+#| Run test cases
+multi sub MAIN('test') {
+ use Test;
+ plan 3;
+
+ is split-string("perl"), False, 'works for "perl"';
+ is split-string("book"), True, 'works for "book"';
+ is split-string("good morning"), True, 'works for "good morning"';
+}
+
+#| Take user provided string like "Perl Weekly Challenge"
+multi sub MAIN(Str $str) {
+ say split-string($str);
+}