From b1a7148f33bd67db6e6704d256e86f64a437ada4 Mon Sep 17 00:00:00 2001 From: BarrOff <58253563+BarrOff@users.noreply.github.com> Date: Sun, 12 May 2024 23:26:18 +0200 Subject: feat: add solutions for challenge 268 from BarrOff --- challenge-268/barroff/julia/ch-1.jl | 15 +++++++++++++++ challenge-268/barroff/raku/ch-1.p6 | 17 +++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 challenge-268/barroff/julia/ch-1.jl create mode 100644 challenge-268/barroff/raku/ch-1.p6 diff --git a/challenge-268/barroff/julia/ch-1.jl b/challenge-268/barroff/julia/ch-1.jl new file mode 100644 index 0000000000..b89b8b45ac --- /dev/null +++ b/challenge-268/barroff/julia/ch-1.jl @@ -0,0 +1,15 @@ +#!/usr/bin/env julia + +using Test: @test, @testset + +function magic_number(x::Vector{T}, y::Vector{T})::Int where {T<:Integer} + return abs(minimum(x) - minimum(y)) + +end + +@testset "magic number" begin + @test magic_number([3, 7, 5], [9, 5, 7]) == 2 + @test magic_number([1, 2, 1], [5, 4, 4]) == 3 + @test magic_number([2], [5]) == 3 +end + diff --git a/challenge-268/barroff/raku/ch-1.p6 b/challenge-268/barroff/raku/ch-1.p6 new file mode 100644 index 0000000000..0282c40358 --- /dev/null +++ b/challenge-268/barroff/raku/ch-1.p6 @@ -0,0 +1,17 @@ +#!/usr/bin/env raku + +use v6.d; + +sub magic-number(@x, @y --> Int:D) { + abs(min(@x) - min(@y)) +} + +#| Run test cases +multi sub MAIN('test') { + use Test; + plan 3; + + is magic-number([3, 7, 5], [9, 5, 7]), 2, 'works for [3, 7, 5] and [9, 5, 7]'; + is magic-number([1, 2, 1], [5, 4, 4]), 3, 'works for [1, 2, 1] and [5, 4, 4]'; + is magic-number([2], [5]), 3, 'works for [2] and [5]'; +} -- cgit