aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-250/nelo-tovar/bash/ch-1.sh34
-rwxr-xr-xchallenge-250/nelo-tovar/bash/ch-2.sh37
-rw-r--r--challenge-250/nelo-tovar/perl/ch-1.pl38
-rw-r--r--challenge-250/nelo-tovar/perl/ch-2.pl39
4 files changed, 148 insertions, 0 deletions
diff --git a/challenge-250/nelo-tovar/bash/ch-1.sh b/challenge-250/nelo-tovar/bash/ch-1.sh
new file mode 100755
index 0000000000..4ebc478a47
--- /dev/null
+++ b/challenge-250/nelo-tovar/bash/ch-1.sh
@@ -0,0 +1,34 @@
+#!/usr/bin/env bash
+#
+# The Weekly Challenge 250 - By Nelo Tovar
+#
+# https://theweeklychallenge.org/blog/perl-weekly-challenge-250/
+#
+# Task 1 : Smallest Index
+
+function smallest_index() {
+ local ints=("$@")
+ local length=${#ints[@]}
+
+ for (( i = 0; i < $length; i++ )); do
+ if [[ $(($i % 10)) -eq ${ints[$i]} ]]; then
+ echo $i
+ return 0
+ fi
+ done
+
+ echo -1
+}
+
+example1='0 1 2'
+example2='4 3 2 1'
+example3='1 2 3 4 5 6 7 8 9 0'
+
+for e in "$example1" "$example2" "$example3"; do
+ array=($e)
+ si=$(smallest_index "${array[@]}")
+ echo "Input : @ints = (${array[@]})"
+ echo "Output : $si"
+ echo ""
+done
+
diff --git a/challenge-250/nelo-tovar/bash/ch-2.sh b/challenge-250/nelo-tovar/bash/ch-2.sh
new file mode 100755
index 0000000000..ccd1ec2f4c
--- /dev/null
+++ b/challenge-250/nelo-tovar/bash/ch-2.sh
@@ -0,0 +1,37 @@
+#!/usr/bin/env bash
+#
+# The Weekly Challenge 250 - By Nelo Tovar
+#
+# https://theweeklychallenge.org/blog/perl-weekly-challenge-250/
+#
+# Task 2 : Alphanumeric String Value
+
+function alphanumeric_string_value() {
+ local alphanumstr=("$@")
+ local max=0
+
+ for x in ${alphanumstr[@]}; do
+ if [[ $x =~ ^[0-9]+$ ]]; then
+ value=$((x + 0 ))
+ else
+ value=${#x}
+ fi
+
+ if [[ $value -gt $max ]]; then
+ max=$value
+ fi
+ done
+
+ echo $max
+}
+
+example1='perl 2 000 python r4ku'
+example2='001 1 000 0001'
+
+for e in "$example1" "$example2"; do
+ array=($e)
+ asv=$(alphanumeric_string_value "${array[@]}")
+ echo "Input : alphanumstr = (${array[@]})"
+ echo -e "Output : $asv\n"
+done
+
diff --git a/challenge-250/nelo-tovar/perl/ch-1.pl b/challenge-250/nelo-tovar/perl/ch-1.pl
new file mode 100644
index 0000000000..44c454ac9f
--- /dev/null
+++ b/challenge-250/nelo-tovar/perl/ch-1.pl
@@ -0,0 +1,38 @@
+#!/usr/bin/env perl
+
+# The Weekly Challenge 250 - By Nelo Tovar
+#
+# https://theweeklychallenge.org/blog/perl-weekly-challenge-250/
+#
+# Task 1 - Smallest Index
+#
+
+use strict;
+use warnings;
+use v5.28;
+use Data::Dump qw(dump);
+
+my @examples = (
+ [ 0, 1, 2 ],
+ [ 4, 3, 2, 1 ],
+ [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 ],
+);
+
+sub smallest_index {
+ my $ints = shift;
+ my $length = scalar @$ints;
+
+ for (my $i = 0; $i < $length; $i++) {
+ return $i if (($i % 10) == $ints->[$i] );
+ }
+
+ return -1;
+}
+
+for my $elements (@examples) {
+ my $si = smallest_index $elements;
+
+ say 'Input : @ints = ', dump(@$elements);
+ say 'Output : ', $si;
+ say ' ';
+}
diff --git a/challenge-250/nelo-tovar/perl/ch-2.pl b/challenge-250/nelo-tovar/perl/ch-2.pl
new file mode 100644
index 0000000000..f587afc974
--- /dev/null
+++ b/challenge-250/nelo-tovar/perl/ch-2.pl
@@ -0,0 +1,39 @@
+#!/usr/bin/env perl
+
+# The Weekly Challenge 250 - By Nelo Tovar
+#
+# https://theweeklychallenge.org/blog/perl-weekly-challenge-250/
+#
+# Task 2 - Alphanumeric String Value
+#
+
+use strict;
+use warnings;
+use v5.28;
+use Data::Dump qw(dump);
+
+my @examples = (
+ [ "perl", "2", "000", "python", "r4ku" ],
+ [ "001", "1", "000", "0001" ],
+);
+
+sub alphanumeric_string_value {
+ my $alphanumstr = shift;
+ my $max = 0;
+
+ foreach my $x (@$alphanumstr) {
+ my $value = ($x =~ /^\d+$/ ? $x + 0 : length $x);
+
+ $max = $value if ( $value > $max)
+ }
+
+ return $max;
+}
+
+for my $elements (@examples) {
+ my $asv = alphanumeric_string_value $elements;
+
+ say 'Input : @alphanumstr = ', dump(@$elements);
+ say 'Output : ', $asv;
+ say ' ';
+}