diff options
| author | BarrOff <58253563+BarrOff@users.noreply.github.com> | 2024-03-17 22:52:49 +0100 |
|---|---|---|
| committer | BarrOff <58253563+BarrOff@users.noreply.github.com> | 2024-03-17 22:52:49 +0100 |
| commit | 5f74a9fd0d45a3f7cad239559ec4153fac698e14 (patch) | |
| tree | ff0d0f8340f8870818620b4e68ee9619c6b8ae72 | |
| parent | 6e7dbc4bfbded8facae0e97c23e62df680d979e4 (diff) | |
| download | perlweeklychallenge-club-5f74a9fd0d45a3f7cad239559ec4153fac698e14.tar.gz perlweeklychallenge-club-5f74a9fd0d45a3f7cad239559ec4153fac698e14.tar.bz2 perlweeklychallenge-club-5f74a9fd0d45a3f7cad239559ec4153fac698e14.zip | |
feat: add solutions and blog for challenge 260 from BarrOff
| -rw-r--r-- | challenge-260/barroff/blog.txt | 1 | ||||
| -rw-r--r-- | challenge-260/barroff/bqn/ch-1.bqn | 9 | ||||
| -rw-r--r-- | challenge-260/barroff/julia/ch-1.jl | 17 | ||||
| -rw-r--r-- | challenge-260/barroff/raku/ch-1.p6 | 25 | ||||
| -rw-r--r-- | challenge-260/barroff/raku/ch-2.p6 | 23 |
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); +} |
