From 0897ce8b47344112a0dcfe12b3c0917317e09555 Mon Sep 17 00:00:00 2001 From: ntovar Date: Sat, 10 Aug 2024 11:42:04 -0500 Subject: Challenge 281. Add Perl (ch-1) and Bash (ch-1) solutions. By Nelo Tovar --- challenge-281/nelo-tovar/bash/ch-1.sh | 28 ++++++++++++++++++++++++++++ challenge-281/nelo-tovar/perl/ch-1.pl | 30 ++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100755 challenge-281/nelo-tovar/bash/ch-1.sh create mode 100644 challenge-281/nelo-tovar/perl/ch-1.pl diff --git a/challenge-281/nelo-tovar/bash/ch-1.sh b/challenge-281/nelo-tovar/bash/ch-1.sh new file mode 100755 index 0000000000..2be89a62a2 --- /dev/null +++ b/challenge-281/nelo-tovar/bash/ch-1.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash +# +# The Weekly Challenge 281 - By Nelo Tovar +# +# https://theweeklychallenge.org/blog/perl-weekly-challenge-281/ +# +# Task 1 - Check Color + +function check_color() { + local coordinates=$1 + + if [[ $coordinates =~ [aceg][1357] ]]; then + echo 'false' + else + echo 'true' + fi +} + +examples=('d3' 'g5' 'e6') + +for e in ${examples[@]}; do + array=($e) + cc=($(check_color $e)) + echo "Input : coordinates = $e" + echo "Output : $cc" + echo "" +done + diff --git a/challenge-281/nelo-tovar/perl/ch-1.pl b/challenge-281/nelo-tovar/perl/ch-1.pl new file mode 100644 index 0000000000..c603eb2aac --- /dev/null +++ b/challenge-281/nelo-tovar/perl/ch-1.pl @@ -0,0 +1,30 @@ +#!/usr/bin/env perl + +# The Weekly Challenge 281 - By Nelo Tovar +# +# https://theweeklychallenge.org/blog/perl-weekly-challenge-281/ +# +# Task 1 - Check Color +# + +use strict; +use warnings; +use v5.28; +use Data::Dump qw(dump); + +my @examples = ( 'd3', 'g5', 'e6'); + +sub check_color { + my $coordinates = shift; + + return ($coordinates =~ /[aceg][1357]/) ? 'false' : 'true'; + +} + +for my $elements (@examples) { + my $cc = check_color $elements; + + say 'Input : coordinates = ', $elements; + say 'Output : ', $cc; + say ' '; +} -- cgit