diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-08-17 18:33:14 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-17 18:33:14 +0100 |
| commit | 1d99ccb8838c7a014927fb640c02a22986f8b4ca (patch) | |
| tree | 39fa66124288137a19f653cc6887616f5e1dc591 | |
| parent | bdd4bb818d8dde2e3210e3aec0f5e81df7b052b6 (diff) | |
| parent | 966629071dec418cad0c0cc5652d5e82559bae00 (diff) | |
| download | perlweeklychallenge-club-1d99ccb8838c7a014927fb640c02a22986f8b4ca.tar.gz perlweeklychallenge-club-1d99ccb8838c7a014927fb640c02a22986f8b4ca.tar.bz2 perlweeklychallenge-club-1d99ccb8838c7a014927fb640c02a22986f8b4ca.zip | |
Merge pull request #10632 from ntovar/branch-282
Challenge 282. Add Perl and Bash solutions. By Nelo Tovar
| -rwxr-xr-x | challenge-282/nelo-tovar/bash/ch-1.sh | 28 | ||||
| -rwxr-xr-x | challenge-282/nelo-tovar/bash/ch-2.sh | 30 | ||||
| -rw-r--r-- | challenge-282/nelo-tovar/perl/ch-1.pl | 28 | ||||
| -rw-r--r-- | challenge-282/nelo-tovar/perl/ch-2.pl | 29 |
4 files changed, 115 insertions, 0 deletions
diff --git a/challenge-282/nelo-tovar/bash/ch-1.sh b/challenge-282/nelo-tovar/bash/ch-1.sh new file mode 100755 index 0000000000..5b2b4a0e0a --- /dev/null +++ b/challenge-282/nelo-tovar/bash/ch-1.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash +# +# The Weekly Challenge 282 - By Nelo Tovar +# +# https://theweeklychallenge.org/blog/perl-weekly-challenge-282/ +# +# Task 1 : Good Integer + +function good_integer() { + local nums=$1 + local match=$(grep -oP '([0-9])\1{2,}' <<< "$nums") + + if [[ ${#match} == 3 ]]; then + echo $match + else + echo -1 + fi +} + +examples=(12344456 1233334 10020003) + +for e in ${examples[@]}; do + gi=($(good_integer "$e")) + echo "Input : nums = $e" + echo "Output : $gi" + echo "" +done + diff --git a/challenge-282/nelo-tovar/bash/ch-2.sh b/challenge-282/nelo-tovar/bash/ch-2.sh new file mode 100755 index 0000000000..848d2b5bd8 --- /dev/null +++ b/challenge-282/nelo-tovar/bash/ch-2.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +# +# The Weekly Challenge 282 - By Nelo Tovar +# +# https://theweeklychallenge.org/blog/perl-weekly-challenge-282/ +# +# Task 2 : Changing Keys + +function changing_keys() { + local nums=$1 + local temp=${nums,,} + local length=${#temp} + declare -A local keys + + for (( i = 0; i < $length; i++ )); do + local digit=${temp:$i:1} + keys[$digit]=1 + done + + echo $((${#keys[@]} - 1)) +} + +examples=('pPeERrLl' 'rRr' 'GoO') + +for e in ${examples[@]}; do + ck=$(changing_keys "$e") + echo "Input : str = $e" + echo -e "Output : $ck\n" +done + diff --git a/challenge-282/nelo-tovar/perl/ch-1.pl b/challenge-282/nelo-tovar/perl/ch-1.pl new file mode 100644 index 0000000000..aa4c0dc128 --- /dev/null +++ b/challenge-282/nelo-tovar/perl/ch-1.pl @@ -0,0 +1,28 @@ +#!/usr/bin/env perl + +# The Weekly Challenge 282 - By Nelo Tovar +# +# https://theweeklychallenge.org/blog/perl-weekly-challenge-282/ +# +# Task 1 - Good Integer +# + +use strict; +use warnings; +use v5.28; + +my @examples = (12344456, 1233334, 10020003); + +sub good_integer { + my $nums = shift; + + return ($nums =~ /((\d) \2{2,})/gx and length $1 == 3) ? $1 : -1; +} + +for my $elements (@examples) { + my $gi = good_integer $elements; + + say 'Input : @nums = ', $elements; + say 'Output : ', $gi; + say ' '; +} diff --git a/challenge-282/nelo-tovar/perl/ch-2.pl b/challenge-282/nelo-tovar/perl/ch-2.pl new file mode 100644 index 0000000000..f2d336e071 --- /dev/null +++ b/challenge-282/nelo-tovar/perl/ch-2.pl @@ -0,0 +1,29 @@ +#!/usr/bin/env perl + +# The Weekly Challenge 282 - By Nelo Tovar +# +# https://theweeklychallenge.org/blog/perl-weekly-challenge-282/ +# +# Task 2 - Changing Keys +# + +use strict; +use warnings; +use v5.28; +use List::MoreUtils qw (uniq); + +my @examples = ('pPeERrLl', 'rRr', 'GoO'); + +sub changing_keys { + my @str = uniq(split(//, lc(shift))); + + return scalar @str - 1; +} + +for my $elements (@examples) { + my $ck = changing_keys $elements; + + say 'Input : str = ', $ck; + say 'Output : ', $ck; + say ' '; +} |
