aboutsummaryrefslogtreecommitdiff
path: root/challenge-283/barroff
diff options
context:
space:
mode:
authorBarrOff <58253563+BarrOff@users.noreply.github.com>2024-08-25 23:45:13 +0200
committerBarrOff <58253563+BarrOff@users.noreply.github.com>2024-08-25 23:45:13 +0200
commit5a5ebc534c5e528823076d0fec49d65fc3c243b9 (patch)
tree87b5d3a2fab36d479c0fe96b2be2c97c4188fff4 /challenge-283/barroff
parentb98782944eb921a476629e62efc3639507cd763a (diff)
downloadperlweeklychallenge-club-5a5ebc534c5e528823076d0fec49d65fc3c243b9.tar.gz
perlweeklychallenge-club-5a5ebc534c5e528823076d0fec49d65fc3c243b9.tar.bz2
perlweeklychallenge-club-5a5ebc534c5e528823076d0fec49d65fc3c243b9.zip
feat: add solutions for challenge 283 from BarrOff
Diffstat (limited to 'challenge-283/barroff')
-rw-r--r--challenge-283/barroff/julia/ch-1.jl17
-rw-r--r--challenge-283/barroff/raku/ch-1.p624
2 files changed, 41 insertions, 0 deletions
diff --git a/challenge-283/barroff/julia/ch-1.jl b/challenge-283/barroff/julia/ch-1.jl
new file mode 100644
index 0000000000..6aa99449bc
--- /dev/null
+++ b/challenge-283/barroff/julia/ch-1.jl
@@ -0,0 +1,17 @@
+#!/usr/bin/env julia
+
+using Test: @test, @testset
+
+function unique_number(ints::Vector{T})::Int where {T<:Integer}
+ numbercounts = Dict{T,Int}()
+ map(x -> numbercounts[x] = get(numbercounts, x, 0) + 1, ints)
+ indices = collect(keys(numbercounts))
+ indices[findfirst(x -> numbercounts[x] == 1, indices)]
+end
+
+@testset "unique number" begin
+ @test unique_number([3, 3, 1]) == 1
+ @test unique_number([3, 2, 4, 2, 4]) == 3
+ @test unique_number([1]) == 1
+ @test unique_number([4, 3, 1, 1, 1, 4]) == 3
+end
diff --git a/challenge-283/barroff/raku/ch-1.p6 b/challenge-283/barroff/raku/ch-1.p6
new file mode 100644
index 0000000000..90a1176017
--- /dev/null
+++ b/challenge-283/barroff/raku/ch-1.p6
@@ -0,0 +1,24 @@
+#!/usr/bin/env raku
+
+use v6.d;
+
+sub unique-number(@ints --> Int) {
+ my %int-bag = Bag(@ints);
+ Int(grep({ %int-bag{$_} == 1 }, %int-bag.keys)[0]);
+}
+
+#| Run test cases
+multi sub MAIN('test') {
+ use Test;
+ plan 4;
+
+ is unique-number([3, 3, 1]), 1, 'works for "(3, 3, 1)"';
+ is unique-number([3, 2, 4, 2, 4]), 3, 'works for "(3, 2, 4, 2, 4)"';
+ is unique-number([1]), 1, 'works for "(1)"';
+ is unique-number([4, 3, 1, 1, 1, 4]), 3, 'works for "(4, 3, 1, 1, 1, 4)"';
+}
+
+#| Take user provided numbers like 4 3 1 1 1 4
+multi sub MAIN(*@ints) {
+ say unique-number(@ints);
+}