aboutsummaryrefslogtreecommitdiff
path: root/challenge-250
diff options
context:
space:
mode:
authorSolathian <horvath6@gmail.com>2025-08-02 16:28:12 +0200
committerSolathian <horvath6@gmail.com>2025-08-02 16:28:12 +0200
commit4014f0eb1fa46f39fee72c2add76ca47f2dd1637 (patch)
tree07ed523115445f773f90f3d0f08c83456457e54e /challenge-250
parent83179303806e75ac6aa4c786cefbb89ab6ddeaf7 (diff)
parent698c027e7ef73ac2753c97d4e64d7fba2b2ddc95 (diff)
downloadperlweeklychallenge-club-4014f0eb1fa46f39fee72c2add76ca47f2dd1637.tar.gz
perlweeklychallenge-club-4014f0eb1fa46f39fee72c2add76ca47f2dd1637.tar.bz2
perlweeklychallenge-club-4014f0eb1fa46f39fee72c2add76ca47f2dd1637.zip
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-250')
-rwxr-xr-xchallenge-250/feng-chang/raku/ch-1.raku5
-rwxr-xr-xchallenge-250/feng-chang/raku/ch-2.raku5
-rwxr-xr-xchallenge-250/feng-chang/raku/test.raku25
-rw-r--r--challenge-250/paulo-custodio/Makefile2
-rw-r--r--challenge-250/paulo-custodio/perl/ch-1.pl48
-rw-r--r--challenge-250/paulo-custodio/perl/ch-2.pl47
-rw-r--r--challenge-250/paulo-custodio/t/test-1.yaml15
-rw-r--r--challenge-250/paulo-custodio/t/test-2.yaml10
-rw-r--r--challenge-250/zapwai/javascript/ch-1.js19
-rw-r--r--challenge-250/zapwai/javascript/ch-2.js23
-rw-r--r--challenge-250/zapwai/python/ch-1.py17
-rw-r--r--challenge-250/zapwai/python/ch-2.py13
12 files changed, 229 insertions, 0 deletions
diff --git a/challenge-250/feng-chang/raku/ch-1.raku b/challenge-250/feng-chang/raku/ch-1.raku
new file mode 100755
index 0000000000..3a94c9f361
--- /dev/null
+++ b/challenge-250/feng-chang/raku/ch-1.raku
@@ -0,0 +1,5 @@
+#!/bin/env raku
+
+unit sub MAIN(*@ints);
+
+with @ints.pairs.map({ .key if .key % 10 == +.value }) { put +$_ ?? .min !! -1 };
diff --git a/challenge-250/feng-chang/raku/ch-2.raku b/challenge-250/feng-chang/raku/ch-2.raku
new file mode 100755
index 0000000000..40a946934c
--- /dev/null
+++ b/challenge-250/feng-chang/raku/ch-2.raku
@@ -0,0 +1,5 @@
+#!/bin/env raku
+
+unit sub MAIN(*@words);
+
+put @words.map({ m/^\d+$/ ?? +$_ !! .chars }).max;
diff --git a/challenge-250/feng-chang/raku/test.raku b/challenge-250/feng-chang/raku/test.raku
new file mode 100755
index 0000000000..f6e6835403
--- /dev/null
+++ b/challenge-250/feng-chang/raku/test.raku
@@ -0,0 +1,25 @@
+#!/bin/env raku
+
+# The Weekly Challenge 250
+use Test;
+
+sub pwc-test(Str:D $script, Bool :$deeply? = False, *@input) {
+ my ($expect, $assertion) = @input.splice(*-2, 2);
+ my $p = run $script, |@input, :out;
+ if $deeply {
+ is-deeply $p.out.slurp(:close).chomp.words.Bag, $expect, $assertion;
+ } else {
+ is $p.out.slurp(:close).chomp, $expect, $assertion;
+ }
+}
+
+# Task 1, Smallest Index
+pwc-test './ch-1.raku', |<0 1 2>, 0, 'Smallest Index: (0, 1, 2) => 0';
+pwc-test './ch-1.raku', |<4 3 2 1>, 2, 'Smallest Index: (4, 3, 2, 1) => 2';
+pwc-test './ch-1.raku', |<1 2 3 4 5 6 7 8 9 0>, -1, 'Smallest Index: (1, 2, 3, 4, 5, 6, 7, 8, 9, 0) => -1';
+
+# Task 2, Alphanumeric String Value
+pwc-test './ch-2.raku', |<perl 2 000 python r4ku>, 6, 'Alphanumeric String Value: ("perl", "2", "000", "python", "r4ku") => 6';
+pwc-test './ch-2.raku', |<001 1 000 0001>, 1, 'Alphanumeric String Value: ("001", "1", "000", "0001") => 1';
+
+done-testing;
diff --git a/challenge-250/paulo-custodio/Makefile b/challenge-250/paulo-custodio/Makefile
new file mode 100644
index 0000000000..c3c762d746
--- /dev/null
+++ b/challenge-250/paulo-custodio/Makefile
@@ -0,0 +1,2 @@
+all:
+ perl ../../challenge-001/paulo-custodio/test.pl
diff --git a/challenge-250/paulo-custodio/perl/ch-1.pl b/challenge-250/paulo-custodio/perl/ch-1.pl
new file mode 100644
index 0000000000..8667ad033c
--- /dev/null
+++ b/challenge-250/paulo-custodio/perl/ch-1.pl
@@ -0,0 +1,48 @@
+#!/usr/bin/env perl
+
+# Challenge 250
+#
+# Task 1: Smallest Index
+# Submitted by: Mohammad S Anwar
+#
+# You are given an array of integers, @ints.
+#
+# Write a script to find the smallest index i such that i mod 10 == $ints[i] otherwise return -1.
+# Example 1
+#
+# Input: @ints = (0, 1, 2)
+# Output: 0
+#
+# i=0: 0 mod 10 = 0 == $ints[0].
+# i=1: 1 mod 10 = 1 == $ints[1].
+# i=2: 2 mod 10 = 2 == $ints[2].
+# All indices have i mod 10 == $ints[i], so we return the smallest index 0.
+#
+# Example 2
+#
+# Input: @ints = (4, 3, 2, 1)
+# Output: 2
+#
+# i=0: 0 mod 10 = 0 != $ints[0].
+# i=1: 1 mod 10 = 1 != $ints[1].
+# i=2: 2 mod 10 = 2 == $ints[2].
+# i=3: 3 mod 10 = 3 != $ints[3].
+# 2 is the only index which has i mod 10 == $ints[i].
+#
+# Example 3
+#
+# Input: @ints = (1, 2, 3, 4, 5, 6, 7, 8, 9, 0)
+# Output: -1
+# Explanation: No index satisfies i mod 10 == $ints[i].
+
+use Modern::Perl;
+
+say smallest_index(@ARGV);
+
+sub smallest_index {
+ my(@ints) = @_;
+ for my $i (0 .. $#ints) {
+ return $i if ($i % 10) == $ints[$i];
+ }
+ return -1;
+}
diff --git a/challenge-250/paulo-custodio/perl/ch-2.pl b/challenge-250/paulo-custodio/perl/ch-2.pl
new file mode 100644
index 0000000000..c0994d31d8
--- /dev/null
+++ b/challenge-250/paulo-custodio/perl/ch-2.pl
@@ -0,0 +1,47 @@
+#!/usr/bin/env perl
+
+# Challenge 250
+#
+# Task 2: Alphanumeric String Value
+# Submitted by: Mohammad S Anwar
+#
+# You are given an array of alphanumeric strings.
+#
+# Write a script to return the maximum value of alphanumeric string in the given array.
+#
+# The value of alphanumeric string can be defined as
+#
+# a) The numeric representation of the string in base 10 if it is made up of digits only.
+# b) otherwise the length of the string
+#
+#
+# Example 1
+#
+# Input: @alphanumstr = ("perl", "2", "000", "python", "r4ku")
+# Output: 6
+#
+# "perl" consists of letters only so the value is 4.
+# "2" is digits only so the value is 2.
+# "000" is digits only so the value is 0.
+# "python" consits of letters so the value is 6.
+# "r4ku" consists of letters and digits so the value is 4.
+#
+# Example 2
+#
+# Input: @alphanumstr = ("001", "1", "000", "0001")
+# Output: 1
+
+use Modern::Perl;
+use List::Util 'max';
+
+say max(map {str_value($_)} @ARGV);
+
+sub str_value {
+ my($str) = @_;
+ if ($str =~ /^\d+$/) {
+ return 0+$str;
+ }
+ else {
+ return length($str);
+ }
+}
diff --git a/challenge-250/paulo-custodio/t/test-1.yaml b/challenge-250/paulo-custodio/t/test-1.yaml
new file mode 100644
index 0000000000..b769218e2d
--- /dev/null
+++ b/challenge-250/paulo-custodio/t/test-1.yaml
@@ -0,0 +1,15 @@
+- setup:
+ cleanup:
+ args: 0 1 2
+ input:
+ output: 0
+- setup:
+ cleanup:
+ args: 4 3 2 1
+ input:
+ output: 2
+- setup:
+ cleanup:
+ args: 1 2 3 4 5 6 7 8 9 0
+ input:
+ output: -1
diff --git a/challenge-250/paulo-custodio/t/test-2.yaml b/challenge-250/paulo-custodio/t/test-2.yaml
new file mode 100644
index 0000000000..0082789893
--- /dev/null
+++ b/challenge-250/paulo-custodio/t/test-2.yaml
@@ -0,0 +1,10 @@
+- setup:
+ cleanup:
+ args: perl 2 000 python r4ku
+ input:
+ output: 6
+- setup:
+ cleanup:
+ args: 001 1 000 0001
+ input:
+ output: 1
diff --git a/challenge-250/zapwai/javascript/ch-1.js b/challenge-250/zapwai/javascript/ch-1.js
new file mode 100644
index 0000000000..250e412f12
--- /dev/null
+++ b/challenge-250/zapwai/javascript/ch-1.js
@@ -0,0 +1,19 @@
+let ints = [0, 1, 2];
+let ints2 = [4, 3, 2, 1];
+let ints3 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
+
+proc(ints);
+proc(ints2);
+proc(ints3);
+
+function proc(ints) {
+ let k = -1;
+ for (let i = 0; i < ints.length; i++) {
+ if (i % 10 == ints[i]) {
+ k = i;
+ break;
+ }
+ }
+ console.log("Input:",ints);
+ console.log("Output:",k);
+}
diff --git a/challenge-250/zapwai/javascript/ch-2.js b/challenge-250/zapwai/javascript/ch-2.js
new file mode 100644
index 0000000000..869729bb7d
--- /dev/null
+++ b/challenge-250/zapwai/javascript/ch-2.js
@@ -0,0 +1,23 @@
+let alph = ["perl", "2", "000", "python", "r4ku"];
+let alph2 = ["001", "1", "000", "0001"];
+
+proc(alph);
+proc(alph2);
+
+function proc(alph) {
+ let max = 0;
+ for (let word of alph) {
+ let reg = /^\d+$/;
+ let n = word.match(reg);
+ if (n == null) {
+ n = word.length;
+ } else {
+ n = Math.max(n);
+ }
+ if (max < n) {
+ max = n;
+ }
+ }
+ console.log("Input:",alph);
+ console.log("Output:",max);
+}
diff --git a/challenge-250/zapwai/python/ch-1.py b/challenge-250/zapwai/python/ch-1.py
new file mode 100644
index 0000000000..5a2619e08c
--- /dev/null
+++ b/challenge-250/zapwai/python/ch-1.py
@@ -0,0 +1,17 @@
+def proc(ints):
+ index = -1
+ for i in range(len(ints)):
+ if i % 10 == ints[i]:
+ index = i
+ break
+ print("Input: ", ints)
+ print("Output: ", index)
+
+ints = [0, 1, 2]
+proc(ints)
+
+ints = [4,3,2,1]
+proc(ints)
+
+ints = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
+proc(ints)
diff --git a/challenge-250/zapwai/python/ch-2.py b/challenge-250/zapwai/python/ch-2.py
new file mode 100644
index 0000000000..b7d48ba00c
--- /dev/null
+++ b/challenge-250/zapwai/python/ch-2.py
@@ -0,0 +1,13 @@
+import re
+def proc(a):
+ nums = list( map( lambda x: len(x), a ) )
+ pattern = r'\b(\d+)\b'
+ for i in range(len(a)):
+ if re.search(pattern,a[i]):
+ nums[i] = int(re.search(pattern, a[i]).group(1))
+ print("Input: ", a)
+ print("Output: ", max(nums))
+a = ("perl", "2", "000", "python", "r4ku");
+proc(a)
+a = ("001", "1", "000", "0001");
+proc(a)