From 43dddc4d84fd76f6c433ac8163f579dda7c6157e Mon Sep 17 00:00:00 2001 From: BarrOff <58253563+BarrOff@users.noreply.github.com> Date: Sun, 11 Aug 2024 22:09:49 +0200 Subject: feat: add solutions for challenge 281 from BarrOff --- challenge-281/barroff/julia/ch-1.jl | 13 +++++++++++++ challenge-281/barroff/raku/ch-1.p6 | 23 +++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 challenge-281/barroff/julia/ch-1.jl create mode 100644 challenge-281/barroff/raku/ch-1.p6 diff --git a/challenge-281/barroff/julia/ch-1.jl b/challenge-281/barroff/julia/ch-1.jl new file mode 100644 index 0000000000..60cb1bfdfe --- /dev/null +++ b/challenge-281/barroff/julia/ch-1.jl @@ -0,0 +1,13 @@ +#!/usr/bin/env julia + +using Test: @test, @testset + +function check_color(str::AbstractString)::Bool + (Int(str[1]) + parse(Int, str[2])) % 2 != 0 +end + +@testset "check color" begin + @test check_color("d3") == true + @test check_color("g5") == false + @test check_color("e6") == true +end diff --git a/challenge-281/barroff/raku/ch-1.p6 b/challenge-281/barroff/raku/ch-1.p6 new file mode 100644 index 0000000000..b7ea968285 --- /dev/null +++ b/challenge-281/barroff/raku/ch-1.p6 @@ -0,0 +1,23 @@ +#!/usr/bin/env raku + +use v6.d; + +sub check-color(Str $coordinates where $coordinates ~~ /^ <[a..h]> <[1..8]> / --> Bool) { + my $translated = $coordinates.trans(['a'..'h'] => ['0'..'7']); + (sum($translated.comb) mod 2) == 0 +} + +#| Run test cases +multi sub MAIN('test') { + use Test; + plan 3; + + is check-color("d3"), True, 'works for "d3"'; + is check-color("g5"), False, 'works for "g5"'; + is check-color("e6"), True, 'works for "e6"'; +} + +#| Take user provided string like "d3" +multi sub MAIN(Str $coordinates where $coordinates ~~ /^ <[a..h]> <[1..8]> /) { + say check-color($coordinates); +} -- cgit