forked from manwar/perlweeklychallenge-club
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request manwar#9455 from steve-g-lynn/branch-for-challenge…
…-253 pwc 253
- Loading branch information
Showing
5 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
https://thiujiac.blogspot.com/2024/01/pwc-253.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |