aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-284/barroff/julia/ch-1.jl16
-rw-r--r--challenge-284/barroff/raku/ch-1.p624
2 files changed, 40 insertions, 0 deletions
diff --git a/challenge-284/barroff/julia/ch-1.jl b/challenge-284/barroff/julia/ch-1.jl
new file mode 100644
index 0000000000..940a4d6815
--- /dev/null
+++ b/challenge-284/barroff/julia/ch-1.jl
@@ -0,0 +1,16 @@
+#!/usr/bin/env julia
+
+using Test: @test, @testset
+
+function lucky_integer(ints::Vector{T})::Int where {T<:Integer}
+ int_dict = Dict{Int,Int}()
+ map(x -> int_dict[x] = get(int_dict, x, 0) + 1, ints)
+ lucky_numbers = filter(x -> int_dict[x] == x, keys(int_dict))
+ return length(lucky_numbers) > 0 ? maximum(lucky_numbers) : -1
+end
+
+@testset "lucky integer" begin
+ @test lucky_integer([2, 2, 3, 4]) == 2
+ @test lucky_integer([1, 2, 2, 3, 3, 3]) == 3
+ @test lucky_integer([1, 1, 1, 3]) == -1
+end
diff --git a/challenge-284/barroff/raku/ch-1.p6 b/challenge-284/barroff/raku/ch-1.p6
new file mode 100644
index 0000000000..54350c5368
--- /dev/null
+++ b/challenge-284/barroff/raku/ch-1.p6
@@ -0,0 +1,24 @@
+#!/usr/bin/env raku
+
+use v6.d;
+
+sub lucky-integer(@ints --> Int) {
+ my %int-bag = Bag(@ints);
+ my @result = grep({ %int-bag{$_} == $_ }, keys %int-bag);
+ @result ?? Int(max(@result)) !! -1;
+}
+
+#| Run test cases
+multi sub MAIN('test') {
+ use Test;
+ plan 3;
+
+ is lucky-integer([2, 2, 3, 4]), 2, 'works for "(2, 2, 3, 4)"';
+ is lucky-integer([1, 2, 2, 3, 3, 3]), 3, 'works for "(1, 2, 2, 3, 3, 3)"';
+ is lucky-integer([1, 1, 1, 3]), -1, 'works for "(1, 1, 1, 3)"';
+}
+
+#| Take user provided numbers like 2 2 3 4
+multi sub MAIN(*@ints) {
+ say lucky-integer(@ints);
+}