aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-250/packy-anderson/README.md68
-rw-r--r--challenge-250/packy-anderson/blog.txt1
-rwxr-xr-xchallenge-250/packy-anderson/perl/ch-1.pl24
-rwxr-xr-xchallenge-250/packy-anderson/perl/ch-2.pl28
-rwxr-xr-xchallenge-250/packy-anderson/python/ch-1.py24
-rwxr-xr-xchallenge-250/packy-anderson/python/ch-2.py28
-rwxr-xr-xchallenge-250/packy-anderson/raku/ch-1.raku24
-rwxr-xr-xchallenge-250/packy-anderson/raku/ch-2.raku26
8 files changed, 156 insertions, 67 deletions
diff --git a/challenge-250/packy-anderson/README.md b/challenge-250/packy-anderson/README.md
index 6682f66637..36982b3432 100644
--- a/challenge-250/packy-anderson/README.md
+++ b/challenge-250/packy-anderson/README.md
@@ -3,83 +3,17 @@
## Raku
* [Task 1](raku/ch-1.raku)
-
-Sample output
-```
-$ raku/ch-1.raku
-Example 1:
-Input: @ints = (3, 2, 3, 2, 2, 2)
-Output: (3, 3), (2, 2), (2, 2)
-
-Example 2:
-Input: @ints = (1, 2, 3, 4)
-Output: ()
-
-Example 3:
-Input: @ints = (1, 2, 3, 4, 4, 3, 2, 1)
-Output: (1, 1), (4, 4), (3, 3), (2, 2)
-```
-
* [Task 2](raku/ch-2.raku)
-Sample output
-```
-$ raku/ch-2.raku
-Example 1:
-Input: $str = 'IDID'
-Output: (0, 4, 1, 3, 2)
-
-Example 2:
-Input: $str = 'III'
-Output: (0, 1, 2, 3)
-
-Example 3:
-Input: $str = 'DDI'
-Output: (3, 2, 0, 1)
-```
-
## Perl
* [Task 1](perl/ch-1.pl)
-
-Sample output
-```
-$ perl/ch-1.pl
-Example 1:
-Input: @ints = (3, 2, 3, 2, 2, 2)
-Output: (2, 2), (2, 2), (3, 3)
-
-Example 2:
-Input: @ints = (1, 2, 3, 4)
-Output: ()
-
-Example 3:
-Input: @ints = (1, 2, 3, 4, 4, 3, 2, 1)
-Output: (4, 4), (3, 3), (2, 2), (1, 1)
-```
-
* [Task 2](perl/ch-2.pl)
-Sample output
-```
-$ perl/ch-2.pl
-Example 1:
-Input: $str = 'IDID'
-Output: (0, 4, 1, 3, 2)
-
-Example 2:
-Input: $str = 'III'
-Output: (0, 1, 2, 3)
-
-Example 3:
-Input: $str = 'DDI'
-Output: (3, 2, 0, 1)
-```
-
## Guest Language: Python
* [Task 1](python/ch-1.py)
* [Task 2](python/ch-2.py)
## Blog Post
-[Perl Weekly Challenge: Stringy DI and Paired Equals](https://packy.dardan.com/b/Fv)
+[Two-Hundred Fifty Perl Weekly Challenges! Two-Hundred Fifty problems so clear...](https://packy.dardan.com/b/G4)
diff --git a/challenge-250/packy-anderson/blog.txt b/challenge-250/packy-anderson/blog.txt
new file mode 100644
index 0000000000..df3e0f5f05
--- /dev/null
+++ b/challenge-250/packy-anderson/blog.txt
@@ -0,0 +1 @@
+https://packy.dardan.com/b/G4 \ No newline at end of file
diff --git a/challenge-250/packy-anderson/perl/ch-1.pl b/challenge-250/packy-anderson/perl/ch-1.pl
new file mode 100755
index 0000000000..6a96d08c32
--- /dev/null
+++ b/challenge-250/packy-anderson/perl/ch-1.pl
@@ -0,0 +1,24 @@
+#!/usr/bin/env perl
+use v5.38;
+
+sub smallestIndex(@ints) {
+ foreach my $i ( 0 .. $#ints ) {
+ return $i if ($i % 10) == $ints[$i];
+ }
+ return -1;
+}
+
+sub solution(@ints) {
+ say 'Input: @ints = (' . join(', ', @ints) . ')';
+ my $smallest = smallestIndex(@ints);
+ say "Output: $smallest";
+}
+
+say "Example 1:";
+solution(0, 1, 2);
+
+say "\nExample 2:";
+solution(4, 3, 2, 1);
+
+say "\nExample 3:";
+solution(1, 2, 3, 4, 5, 6, 7, 8, 9, 0); \ No newline at end of file
diff --git a/challenge-250/packy-anderson/perl/ch-2.pl b/challenge-250/packy-anderson/perl/ch-2.pl
new file mode 100755
index 0000000000..a809e47886
--- /dev/null
+++ b/challenge-250/packy-anderson/perl/ch-2.pl
@@ -0,0 +1,28 @@
+#!/usr/bin/env perl
+use v5.38;
+
+use List::Util qw( max );
+
+sub alphanumValue($str) {
+ if ($str =~ /^\d+$/) {
+ return $str + 0;
+ }
+ return length($str);
+}
+
+sub maxAlphanumValue(@alphanumstr) {
+ my @values = map { alphanumValue($_) } @alphanumstr;
+ return max(@values);
+}
+
+sub solution(@alphanumstr) {
+ say 'Input: @alphanumstr = ("' . join('", "', @alphanumstr) . '")';
+ my $maxValue = maxAlphanumValue(@alphanumstr);
+ say "Output: $maxValue";
+}
+
+say "Example 1:";
+solution("perl", "2", "000", "python", "r4ku");
+
+say "\nExample 2:";
+solution("001", "1", "000", "0001"); \ No newline at end of file
diff --git a/challenge-250/packy-anderson/python/ch-1.py b/challenge-250/packy-anderson/python/ch-1.py
new file mode 100755
index 0000000000..4db4b59bd5
--- /dev/null
+++ b/challenge-250/packy-anderson/python/ch-1.py
@@ -0,0 +1,24 @@
+#!/usr/bin/env python
+
+def smallestIndex(ints):
+ for i in range(len(ints)):
+ if (i % 10) == ints[i]:
+ return i
+ return -1
+
+def comma_join(arr):
+ return ', '.join(map(lambda i: str(i), arr))
+
+def solution(ints):
+ print(f'Input: @ints = ({comma_join(ints)})')
+ smallest = smallestIndex(ints)
+ print(f'Output: {smallest}')
+
+print('Example 1:')
+solution([0, 1, 2])
+
+print('\nExample 2:')
+solution([4, 3, 2, 1])
+
+print('\nExample 3:')
+solution([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) \ No newline at end of file
diff --git a/challenge-250/packy-anderson/python/ch-2.py b/challenge-250/packy-anderson/python/ch-2.py
new file mode 100755
index 0000000000..b54a2c24d3
--- /dev/null
+++ b/challenge-250/packy-anderson/python/ch-2.py
@@ -0,0 +1,28 @@
+#!/usr/bin/env python
+
+import re
+
+is_numeric = re.compile('^\d+$')
+
+def alphanumValue(strval):
+ if (is_numeric.match(strval)):
+ return int(strval)
+ return len(strval)
+
+def maxAlphanumValue(alphanumstr):
+ values = [ alphanumValue(x) for x in alphanumstr ]
+ return max(values)
+
+def comma_join(arr):
+ return '"' + '", "'.join(arr) + '"'
+
+def solution(alphanumstr):
+ print(f'Input: @alphanumstr = ({comma_join(alphanumstr)})')
+ maxValue = maxAlphanumValue(alphanumstr)
+ print(f'Output: {maxValue}')
+
+print('Example 1:')
+solution(["perl", "2", "000", "python", "r4ku"])
+
+print('\nExample 2:')
+solution(["001", "1", "000", "0001"]) \ No newline at end of file
diff --git a/challenge-250/packy-anderson/raku/ch-1.raku b/challenge-250/packy-anderson/raku/ch-1.raku
new file mode 100755
index 0000000000..2f57207b1b
--- /dev/null
+++ b/challenge-250/packy-anderson/raku/ch-1.raku
@@ -0,0 +1,24 @@
+#!/usr/bin/env raku
+use v6;
+
+sub smallestIndex(@ints) {
+ for 0 .. @ints.end -> $i {
+ return $i if ($i mod 10) == @ints[$i];
+ }
+ return -1;
+}
+
+sub solution(@ints) {
+ say 'Input: @ints = (' ~ @ints.join(', ') ~ ')';
+ my $smallest = smallestIndex(@ints);
+ say "Output: $smallest";
+}
+
+say "Example 1:";
+solution([0, 1, 2]);
+
+say "\nExample 2:";
+solution([4, 3, 2, 1]);
+
+say "\nExample 3:";
+solution([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]); \ No newline at end of file
diff --git a/challenge-250/packy-anderson/raku/ch-2.raku b/challenge-250/packy-anderson/raku/ch-2.raku
new file mode 100755
index 0000000000..60fe1e3a34
--- /dev/null
+++ b/challenge-250/packy-anderson/raku/ch-2.raku
@@ -0,0 +1,26 @@
+#!/usr/bin/env raku
+use v6;
+
+sub alphanumValue($str) {
+ if ($str ~~ /^\d+$/) {
+ return Int($str);
+ }
+ return $str.chars;
+}
+
+sub maxAlphanumValue(@alphanumstr) {
+ my @values = @alphanumstr.map({ alphanumValue($_) });
+ return @values.max;
+}
+
+sub solution(@alphanumstr) {
+ say 'Input: @alphanumstr = ("' ~ @alphanumstr.join('", "') ~ '")';
+ my $maxValue = maxAlphanumValue(@alphanumstr);
+ say "Output: $maxValue";
+}
+
+say "Example 1:";
+solution(["perl", "2", "000", "python", "r4ku"]);
+
+say "\nExample 2:";
+solution(["001", "1", "000", "0001"]); \ No newline at end of file