diff options
| -rw-r--r-- | challenge-253/steve-g-lynn/blog.txt | 1 | ||||
| -rw-r--r-- | challenge-253/steve-g-lynn/perl/ch-1.pl | 32 | ||||
| -rw-r--r-- | challenge-253/steve-g-lynn/perl/ch-2.pl | 26 | ||||
| -rw-r--r-- | challenge-253/steve-g-lynn/python/ch-1.py | 20 | ||||
| -rw-r--r-- | challenge-253/steve-g-lynn/python/ch-2.py | 18 |
5 files changed, 97 insertions, 0 deletions
diff --git a/challenge-253/steve-g-lynn/blog.txt b/challenge-253/steve-g-lynn/blog.txt new file mode 100644 index 0000000000..88e01acfc1 --- /dev/null +++ b/challenge-253/steve-g-lynn/blog.txt @@ -0,0 +1 @@ +https://thiujiac.blogspot.com/2024/01/pwc-253.html diff --git a/challenge-253/steve-g-lynn/perl/ch-1.pl b/challenge-253/steve-g-lynn/perl/ch-1.pl new file mode 100644 index 0000000000..af36e4b7b6 --- /dev/null +++ b/challenge-253/steve-g-lynn/perl/ch-1.pl @@ -0,0 +1,32 @@ +# Perl 4.019 on DOSBOX
+
+sub split_strings {
+ local ($separator, @words)=@_;
+ local (@retval)=(); #array to be returned
+
+ #-- prefix $separator with '\\' to escape it in case it is
+ #-- a meaningful regex character like '.' or '$'
+
+ $separator = '\\' . $separator;
+ local (@split_strings)=();
+
+ foreach (@words) {
+
+ @split_strings = split(/$separator/,$_);
+
+ foreach (@split_strings) {
+
+ #-- push to @retval only if item is not an empty string
+ $_ && push( @retval, $_ );
+
+ }
+
+ }
+ @retval;
+}
+
+print join( ",", &split_strings('.', 'one.two.three', 'four.five', 'six') ),"\n";
+#one,two,three,four,five,six
+
+print join( ",", &split_strings('$', '$perl$$', '$$raku$') ),"\n";
+#perl,raku
diff --git a/challenge-253/steve-g-lynn/perl/ch-2.pl b/challenge-253/steve-g-lynn/perl/ch-2.pl new file mode 100644 index 0000000000..5e67272a53 --- /dev/null +++ b/challenge-253/steve-g-lynn/perl/ch-2.pl @@ -0,0 +1,26 @@ +#perl 4.019 on DOSBOX
+
+sub mysum {
+ local(@mysum)=split(//,$_[0]);
+ local($mysum)=0;
+ foreach (@mysum){
+ $mysum += $_;
+ }
+ $mysum;
+}
+
+sub weakest_row {
+ #input valuation
+ local($weakest_row) = length($_[0]);
+ foreach (@_) {
+ ($_ =~ /^[01]+$/) || (die "Input error: $!\n");
+ (length($_) == $weakest_row) || (die "Not a matrix: $!\n");
+ }
+
+ sort { (&mysum($_[$a]) <=> &mysum($_[$b])) ||
+ ($a <=> $b);
+ } 0 .. $#_;
+}
+
+print join( ",", &weakest_row('11000','11110','10000','11000','11111') ),"\n";
+print join( ",", &weakest_row('1000','1111','1000','1000') ), "\n";
diff --git a/challenge-253/steve-g-lynn/python/ch-1.py b/challenge-253/steve-g-lynn/python/ch-1.py new file mode 100644 index 0000000000..bc625f1ae2 --- /dev/null +++ b/challenge-253/steve-g-lynn/python/ch-1.py @@ -0,0 +1,20 @@ +
+# Python 1.4 beta on DOSBOX
+
+import string
+
+def split_strings(arrStr, sep):
+ retval=[] #array to be returned
+ for str in arrStr:
+ str_split=string.splitfields( str, sep )
+ for item in str_split:
+ if (item != ""):
+ retval.append(item)
+ return retval
+
+print split_strings(("one.two.three","four.five","six"),".")
+#['one','two','three','four','five','six']
+
+print split_strings(("$perl$$","$$raku$"),"$")
+#['perl','raku']
+
diff --git a/challenge-253/steve-g-lynn/python/ch-2.py b/challenge-253/steve-g-lynn/python/ch-2.py new file mode 100644 index 0000000000..9576282653 --- /dev/null +++ b/challenge-253/steve-g-lynn/python/ch-2.py @@ -0,0 +1,18 @@ +# python 1.4 beta on DOSBOX
+
+def mysum(arr10):
+ return reduce(lambda x1, x2: x1+x2, arr10)
+
+def weakest_row(matrix): #-- matrix is an array of arrays
+ retval=[]
+ for rowno in range(len(matrix)): #for each row
+ retval.append((mysum(matrix[rowno]),rowno))
+ retval.sort()
+ return map(lambda x:x[1],retval)
+
+
+print weakest_row([[1,1,0,0,0],[1,1,1,1,0],[1,0,0,0,0],[1,1,0,0,0],[1,1,1,1,1]])
+#[2, 0, 3, 1, 4]
+
+print weakest_row([[1,0,0,0],[1,1,1,1],[1,0,0,0],[1,0,0,0]])
+#[0, 2, 3, 1]
|
