aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-01-28 16:35:02 +0000
committerGitHub <noreply@github.com>2024-01-28 16:35:02 +0000
commitcda5876d6dad1b64c91468748dc3be4d708d0789 (patch)
tree951d6076d21867cfa80ce8d5a28df9f879083235
parentb0a63aa82682515ac8c9aee1cb582d14245eb501 (diff)
parent6c2c00e692c0c6d5363619da47d76165ab6174ac (diff)
downloadperlweeklychallenge-club-cda5876d6dad1b64c91468748dc3be4d708d0789.tar.gz
perlweeklychallenge-club-cda5876d6dad1b64c91468748dc3be4d708d0789.tar.bz2
perlweeklychallenge-club-cda5876d6dad1b64c91468748dc3be4d708d0789.zip
Merge pull request #9473 from wambash/challenge-week-253
Challenge week 253
-rw-r--r--challenge-253/wambash/elixir/ch-1.exs19
-rw-r--r--challenge-253/wambash/elixir/ch-2.exs35
-rw-r--r--challenge-253/wambash/julia/ch-1.jl10
-rw-r--r--challenge-253/wambash/julia/ch-2.jl35
-rw-r--r--challenge-253/wambash/raku/ch-1.raku16
-rw-r--r--challenge-253/wambash/raku/ch-2.raku32
6 files changed, 147 insertions, 0 deletions
diff --git a/challenge-253/wambash/elixir/ch-1.exs b/challenge-253/wambash/elixir/ch-1.exs
new file mode 100644
index 0000000000..b0de266bb9
--- /dev/null
+++ b/challenge-253/wambash/elixir/ch-1.exs
@@ -0,0 +1,19 @@
+defmodule Strings do
+ def split(words, separator \\ " ") do
+ words |> Enum.flat_map(&String.split(&1,separator,trim: true))
+ end
+end
+
+
+ExUnit.start()
+
+defmodule StringsTest do
+ use ExUnit.Case
+
+ test "Split strings" do
+ assert Strings.split(["one.two.three","four.five","six"],".") == ["one","two","three","four","five","six"]
+ end
+ test "Split strings need trim" do
+ assert Strings.split(["$perl$$", "$$raku$"],"$") == ["perl","raku"]
+ end
+end
diff --git a/challenge-253/wambash/elixir/ch-2.exs b/challenge-253/wambash/elixir/ch-2.exs
new file mode 100644
index 0000000000..b725f2a09c
--- /dev/null
+++ b/challenge-253/wambash/elixir/ch-2.exs
@@ -0,0 +1,35 @@
+defmodule Matrix do
+ def weekest_row(matrix) do
+ matrix
+ |> Enum.with_index
+ |> Enum.sort
+ |> Enum.map( fn {_,index} -> index end)
+ end
+end
+
+ExUnit.start()
+
+defmodule MatrixTest do
+ use ExUnit.Case
+ test "Matrix" do
+ matrix = [
+ [1, 1, 0, 0, 0],
+ [1, 1, 1, 1, 0],
+ [1, 0, 0, 0, 0],
+ [1, 1, 0, 0, 0],
+ [1, 1, 1, 1, 1]
+ ]
+ assert Matrix.weekest_row(matrix) == [2,0,3,1,4]
+
+ end
+ test "Matrix same rows" do
+ matrix = [
+ [1, 0, 0, 0],
+ [1, 1, 1, 1],
+ [1, 0, 0, 0],
+ [1, 0, 0, 0],
+ ]
+ assert Matrix.weekest_row(matrix) == [0,2,3,1]
+
+ end
+end
diff --git a/challenge-253/wambash/julia/ch-1.jl b/challenge-253/wambash/julia/ch-1.jl
new file mode 100644
index 0000000000..e28766555b
--- /dev/null
+++ b/challenge-253/wambash/julia/ch-1.jl
@@ -0,0 +1,10 @@
+#!/usr/bin/env julia
+
+split_strings(words; separator = " " ) = mapreduce( x -> split(x, separator, keepempty=false ), vcat, words)
+
+using Test
+
+@testset "split strings" begin
+ @test split_strings(["one.two.three","four.five","six"], separator = ".") == ["one","two","three","four","five","six"]
+ @test split_strings(["\$perl\$\$", "\$\$raku\$"], separator = "\$") == ["perl","raku"]
+end
diff --git a/challenge-253/wambash/julia/ch-2.jl b/challenge-253/wambash/julia/ch-2.jl
new file mode 100644
index 0000000000..681f45f6c8
--- /dev/null
+++ b/challenge-253/wambash/julia/ch-2.jl
@@ -0,0 +1,35 @@
+#!/usr/bin/env julia
+
+using Lazy
+
+weakest_row(matrix) = @>> begin
+ matrix
+ pairs
+ collect
+ map(reverse)
+ sort
+ map(x-> x.second - 1)
+end
+
+using Test
+
+@testset "Matrix" begin
+ matrix = [
+ [1, 1, 0, 0, 0],
+ [1, 1, 1, 1, 0],
+ [1, 0, 0, 0, 0],
+ [1, 1, 0, 0, 0],
+ [1, 1, 1, 1, 1]
+ ]
+ @test weakest_row(matrix) == [2,0,3,1,4]
+end
+
+@testset "Matrix with same rows" begin
+ matrix = [
+ [1, 0, 0, 0],
+ [1, 1, 1, 1],
+ [1, 0, 0, 0],
+ [1, 0, 0, 0],
+ ]
+ @test weakest_row(matrix) == [0,2,3,1]
+end
diff --git a/challenge-253/wambash/raku/ch-1.raku b/challenge-253/wambash/raku/ch-1.raku
new file mode 100644
index 0000000000..8bb99a0cfd
--- /dev/null
+++ b/challenge-253/wambash/raku/ch-1.raku
@@ -0,0 +1,16 @@
+#!/usr/bin/env raku
+
+sub split-string (+words, :$separator=q{ }) {
+ words.map: |*.split($separator, :skip-empty )
+}
+
+multi MAIN (Bool :test($)!) {
+ use Test;
+ is-deeply split-string(<one.two.three four.five six>):separator('.'), <one two three four five six>;
+ is-deeply split-string(<$perl$$ $$raku$>):separator('$'),<perl raku>;
+ done-testing;
+}
+
+multi MAIN (+words, :$separator=q{ }) {
+ put split-string words, :$separator
+}
diff --git a/challenge-253/wambash/raku/ch-2.raku b/challenge-253/wambash/raku/ch-2.raku
new file mode 100644
index 0000000000..f48df8ca77
--- /dev/null
+++ b/challenge-253/wambash/raku/ch-2.raku
@@ -0,0 +1,32 @@
+#!/usr/bin/env raku
+
+sub weekest-row (+matrix) {
+ matrix
+ andthen .antipairs
+ andthen .sort
+ andthen .map: *.value
+}
+
+multi MAIN (Bool :test($)!) {
+ use Test;
+ my @matrix := [
+ [1, 1, 0, 0, 0],
+ [1, 1, 1, 1, 0],
+ [1, 0, 0, 0, 0],
+ [1, 1, 0, 0, 0],
+ [1, 1, 1, 1, 1]
+ ];
+ is weekest-row(@matrix),(2,0,3,1,4);
+ my @matrix2 := [
+ [1, 0, 0, 0],
+ [1, 1, 1, 1],
+ [1, 0, 0, 0],
+ [1, 0, 0, 0]
+ ];
+ is weekest-row(@matrix2), (0,2,3,1);
+ done-testing;
+}
+
+multi MAIN (+matrix) {
+ put weekest-row matrix».comb: /\d/;
+}