aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-08-11 21:44:45 +0100
committerGitHub <noreply@github.com>2024-08-11 21:44:45 +0100
commitc3a4e8b9a3e0424acc4dde3748f975160311fac3 (patch)
tree1eb808f4d179ef2bf01a7008e2ad3df3c5e8dc87
parenteb428248d7b759d66ec55febd16c3d947b80f828 (diff)
parent43dddc4d84fd76f6c433ac8163f579dda7c6157e (diff)
downloadperlweeklychallenge-club-c3a4e8b9a3e0424acc4dde3748f975160311fac3.tar.gz
perlweeklychallenge-club-c3a4e8b9a3e0424acc4dde3748f975160311fac3.tar.bz2
perlweeklychallenge-club-c3a4e8b9a3e0424acc4dde3748f975160311fac3.zip
Merge pull request #10584 from BarrOff/barroff-281
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);
+}