aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBarrOff <58253563+BarrOff@users.noreply.github.com>2024-08-11 22:09:49 +0200
committerBarrOff <58253563+BarrOff@users.noreply.github.com>2024-08-11 22:09:49 +0200
commit43dddc4d84fd76f6c433ac8163f579dda7c6157e (patch)
treea2c68177294ba75ee4273c9678a0494ba6952502
parentb7440fc8a1cedf364f75a0a846ee8eb3e63cb158 (diff)
downloadperlweeklychallenge-club-43dddc4d84fd76f6c433ac8163f579dda7c6157e.tar.gz
perlweeklychallenge-club-43dddc4d84fd76f6c433ac8163f579dda7c6157e.tar.bz2
perlweeklychallenge-club-43dddc4d84fd76f6c433ac8163f579dda7c6157e.zip
feat: add solutions for challenge 281 from BarrOff
-rw-r--r--challenge-281/barroff/julia/ch-1.jl13
-rw-r--r--challenge-281/barroff/raku/ch-1.p623
2 files changed, 36 insertions, 0 deletions
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);
+}