aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-03-18 00:43:46 +0000
committerGitHub <noreply@github.com>2024-03-18 00:43:46 +0000
commit521060f298b5fcf776dd45d82dc046d6e8f4e6cb (patch)
tree1c2fa888ddc75432d3baa033a19edecd69e25c8b
parent247a9e1ba66ed42c21849ddaf5b21e499d9e1f14 (diff)
parent5f74a9fd0d45a3f7cad239559ec4153fac698e14 (diff)
downloadperlweeklychallenge-club-521060f298b5fcf776dd45d82dc046d6e8f4e6cb.tar.gz
perlweeklychallenge-club-521060f298b5fcf776dd45d82dc046d6e8f4e6cb.tar.bz2
perlweeklychallenge-club-521060f298b5fcf776dd45d82dc046d6e8f4e6cb.zip
Merge pull request #9758 from BarrOff/barroff-260
feat: add solutions and blog for challenge 260 from BarrOff
-rw-r--r--challenge-260/barroff/blog.txt1
-rw-r--r--challenge-260/barroff/bqn/ch-1.bqn9
-rw-r--r--challenge-260/barroff/julia/ch-1.jl17
-rw-r--r--challenge-260/barroff/raku/ch-1.p625
-rw-r--r--challenge-260/barroff/raku/ch-2.p623
5 files changed, 75 insertions, 0 deletions
diff --git a/challenge-260/barroff/blog.txt b/challenge-260/barroff/blog.txt
new file mode 100644
index 0000000000..6dd046bacb
--- /dev/null
+++ b/challenge-260/barroff/blog.txt
@@ -0,0 +1 @@
+https://barroff.codeberg.page/2024/03/occurrences-with-bqn/
diff --git a/challenge-260/barroff/bqn/ch-1.bqn b/challenge-260/barroff/bqn/ch-1.bqn
new file mode 100644
index 0000000000..74490ca6c5
--- /dev/null
+++ b/challenge-260/barroff/bqn/ch-1.bqn
@@ -0,0 +1,9 @@
+#/usr/bin/env bqn
+
+ints ← 2‿5‿9‿11‿3
+
+UniqueOccurrences ← ∧´∘∊(+´˘(∊/⊢)=⌜⊢)
+
+•Show UniqueOccurrences ⟨1,2,2,1,1,3⟩
+•Show UniqueOccurrences ⟨1,2,3⟩
+•Show UniqueOccurrences ⟨-2,0,1,-2,1,1,0,1,-2,9⟩
diff --git a/challenge-260/barroff/julia/ch-1.jl b/challenge-260/barroff/julia/ch-1.jl
new file mode 100644
index 0000000000..2de40cc3b6
--- /dev/null
+++ b/challenge-260/barroff/julia/ch-1.jl
@@ -0,0 +1,17 @@
+#!/usr/bin/env julia
+
+using Test: @test, @testset
+
+function unique_values(ints::Vector{T})::Int where {T<:Integer}
+ unique_numbers = unique(ints)
+ Int(
+ length(unique_numbers) ==
+ length(unique(map(x -> count(y -> y == x, ints), unique_numbers))),
+ )
+end
+
+@testset "count even digits number" begin
+ @test unique_values([1, 2, 2, 1, 1, 3]) == 1
+ @test unique_values([1, 2, 3]) == 0
+ @test unique_values([-2, 0, 1, -2, 1, 1, 0, 1, -2, 9]) == 1
+end
diff --git a/challenge-260/barroff/raku/ch-1.p6 b/challenge-260/barroff/raku/ch-1.p6
new file mode 100644
index 0000000000..de0c15d531
--- /dev/null
+++ b/challenge-260/barroff/raku/ch-1.p6
@@ -0,0 +1,25 @@
+#!/usr/bin/env raku
+
+use v6.d;
+
+sub unique-occurrences(@ints --> Int:D) {
+ my @bag_values = Bag(@ints).values;
+ @bag_values.unique.elems == @bag_values.elems ?? 1 !! 0;
+}
+
+#| Run test cases
+multi sub MAIN('test') {
+ use Test;
+ plan 3;
+
+ is unique-occurrences([1,2,2,1,1,3]), 1, 'works for (1,2,2,1,1,3)';
+ is unique-occurrences([1,2,3]), 0, 'works for (1,2,3)';
+ is unique-occurrences([-2,0,1,-2,1,1,0,1,-2,9]), 1,
+ 'works for (-2,0,1,-2,1,1,0,1,-2,9)';
+}
+
+#| Take user provided number like 10 1 111 24 1000
+multi sub MAIN(*@ints) {
+ say unique-occurrences(@ints);
+}
+
diff --git a/challenge-260/barroff/raku/ch-2.p6 b/challenge-260/barroff/raku/ch-2.p6
new file mode 100644
index 0000000000..2dc3407f99
--- /dev/null
+++ b/challenge-260/barroff/raku/ch-2.p6
@@ -0,0 +1,23 @@
+#!/usr/bin/env raku
+
+use v6.d;
+
+sub dictionary-rank(Str:D $word --> Int:D) {
+ my @words = $word.comb.permutations.map({ $_.join }).unique.sort;
+ return 1 + @words.first: * eq $word, :k;
+}
+
+#| Run test cases
+multi sub MAIN('test') {
+ use Test;
+ plan 3;
+
+ is dictionary-rank("CAT"), 3, 'works for "CAT"';
+ is dictionary-rank("GOOGLE"), 88, 'works for "GOOGLE"';
+ is dictionary-rank("SECRET"), 255, 'works for "SECRET"';
+}
+
+#| Take user provided words like CAT
+multi sub MAIN(Str:D $word) {
+ say dictionary-rank($word);
+}