Skip to content

Commit

Permalink
Merge pull request manwar#9455 from steve-g-lynn/branch-for-challenge…
Browse files Browse the repository at this point in the history
…-253

pwc 253
  • Loading branch information
manwar authored Jan 23, 2024
2 parents b5525a2 + 8d0a98a commit cb13cb5
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 0 deletions.
1 change: 1 addition & 0 deletions challenge-253/steve-g-lynn/blog.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://thiujiac.blogspot.com/2024/01/pwc-253.html
32 changes: 32 additions & 0 deletions challenge-253/steve-g-lynn/perl/ch-1.pl
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions challenge-253/steve-g-lynn/perl/ch-2.pl
Original file line number Diff line number Diff line change
@@ -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";
20 changes: 20 additions & 0 deletions challenge-253/steve-g-lynn/python/ch-1.py
Original file line number Diff line number Diff line change
@@ -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']

18 changes: 18 additions & 0 deletions challenge-253/steve-g-lynn/python/ch-2.py
Original file line number Diff line number Diff line change
@@ -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]

0 comments on commit cb13cb5

Please sign in to comment.