diff options
| -rw-r--r-- | challenge-285/barroff/julia/ch-1.jl | 16 | ||||
| -rw-r--r-- | challenge-285/barroff/raku/ch-1.p6 | 29 |
2 files changed, 45 insertions, 0 deletions
diff --git a/challenge-285/barroff/julia/ch-1.jl b/challenge-285/barroff/julia/ch-1.jl new file mode 100644 index 0000000000..940a4d6815 --- /dev/null +++ b/challenge-285/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-285/barroff/raku/ch-1.p6 b/challenge-285/barroff/raku/ch-1.p6 new file mode 100644 index 0000000000..e7e6a5402f --- /dev/null +++ b/challenge-285/barroff/raku/ch-1.p6 @@ -0,0 +1,29 @@ +#!/usr/bin/env raku + +use v6.d; + +sub no-connection(@routes --> Str) { + my %routes-dict; + map({ %routes-dict{$_[0]} = $_[1] }, @routes); + my $sources = Set(keys(%routes-dict)); + my $targets = Set(values(%routes-dict)); + keys($targets (-) $sources)[0]; +} + +#| Run test cases +multi sub MAIN('test') { + use Test; + plan 2; + + is no-connection([["B","C"], ["D","B"], ["C","A"]]), "A", 'works for route one'; + is no-connection([["A","Z"],]), "Z", 'works for route two'; +} + +#| Take user provided list like B C D B C A +multi sub MAIN(*@routes where elems(@routes) mod 2 == 0) { + my @pr; + for @routes -> $source, $target { + @pr.push([$source, $target]); + } + say no-connection(@pr); +} |
