aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBarrOff <58253563+BarrOff@users.noreply.github.com>2024-04-21 21:22:26 +0200
committerBarrOff <58253563+BarrOff@users.noreply.github.com>2024-04-21 21:22:26 +0200
commit8c4a5abbd2036bbbe79bcaa7a23f6c9071365ceb (patch)
tree692a9efaf154d8582a37a4481e9ca2bae0043de5
parent6e0b5101539f2dc9f4b46a37f6d15ba8b4637197 (diff)
downloadperlweeklychallenge-club-8c4a5abbd2036bbbe79bcaa7a23f6c9071365ceb.tar.gz
perlweeklychallenge-club-8c4a5abbd2036bbbe79bcaa7a23f6c9071365ceb.tar.bz2
perlweeklychallenge-club-8c4a5abbd2036bbbe79bcaa7a23f6c9071365ceb.zip
feat: add solutions for challenge 265 from BarrOff
-rw-r--r--challenge-265/barroff/julia/ch-1.jl19
-rw-r--r--challenge-265/barroff/raku/ch-1.p626
2 files changed, 45 insertions, 0 deletions
diff --git a/challenge-265/barroff/julia/ch-1.jl b/challenge-265/barroff/julia/ch-1.jl
new file mode 100644
index 0000000000..918418d8dd
--- /dev/null
+++ b/challenge-265/barroff/julia/ch-1.jl
@@ -0,0 +1,19 @@
+#!/usr/bin/env julia
+
+using Test: @test, @testset
+
+function thirtythree_appearance(ints::Vector{T})::T where {T<:Integer}
+ third = length(ints) / 3
+ thirds = filter(x -> count(y -> y == x, ints) ≥ third, unique(ints))
+ if length(thirds) > 0
+ return minimum(thirds)
+ end
+ return NaN
+
+end
+
+@testset "33% appearance" begin
+ @test thirtythree_appearance([1, 2, 3, 3, 3, 3, 4, 2]) == 3
+ @test thirtythree_appearance([1, 1]) == 1
+ @test thirtythree_appearance([1, 2, 3]) == 1
+end
diff --git a/challenge-265/barroff/raku/ch-1.p6 b/challenge-265/barroff/raku/ch-1.p6
new file mode 100644
index 0000000000..72d697d65c
--- /dev/null
+++ b/challenge-265/barroff/raku/ch-1.p6
@@ -0,0 +1,26 @@
+#!/usr/bin/env raku
+
+use v6.d;
+
+sub thirtythree-appearance(@ints) {
+ my %int-bag = @ints.Bag;
+ my $third = @ints.elems ÷ 3;
+ my @smallest-appearances = grep({ %int-bag{$_} ≥ $third }, %int-bag.keys);
+ return @smallest-appearances.min.Int if @smallest-appearances;
+ return Any;
+}
+
+#| Run test cases
+multi sub MAIN('test') {
+ use Test;
+ plan 3;
+
+ is thirtythree-appearance([1,2,3,3,3,3,4,2]), 3, 'works for (1,2,3,3,3,3,4,2)';
+ is thirtythree-appearance([1, 1]), 1, 'works for (1, 1)';
+ is thirtythree-appearance([1, 2, 3]), 1, 'works for (1, 2, 3)';
+}
+
+#| Take user provided number like 10 1 111 24 1000
+multi sub MAIN(*@ints) {
+ say thirtythree-appearance(@ints);
+}