diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-09-08 22:42:18 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-08 22:42:18 +0100 |
| commit | 9e5e6eb86855ae99fcc724fb49c9d60eeeb61c21 (patch) | |
| tree | 7ba42136a5358b11f6b9793f021683f8e8cdc364 | |
| parent | 725c6b87d5c76d5cd8fef6b30a2979c84c16eb9e (diff) | |
| parent | 46225527812d72f97e0c03a30a0e6056889af831 (diff) | |
| download | perlweeklychallenge-club-9e5e6eb86855ae99fcc724fb49c9d60eeeb61c21.tar.gz perlweeklychallenge-club-9e5e6eb86855ae99fcc724fb49c9d60eeeb61c21.tar.bz2 perlweeklychallenge-club-9e5e6eb86855ae99fcc724fb49c9d60eeeb61c21.zip | |
Merge pull request #10796 from BarrOff/barroff-285
feat: add solutions for challenge 285 from BarrOff
| -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); +} |
