diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-01-10 16:57:21 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-01-10 16:57:21 +0000 |
| commit | 4e5a407712af3485999e3ad353019e7f6517c063 (patch) | |
| tree | 897a48816381633fb17a26ffcfbb96065609b579 | |
| parent | 4e661c6f105e3bdbb5f3236252d5cef746fc0fa8 (diff) | |
| parent | 4c16694f258dc06c54021def82082f75a1a55d9e (diff) | |
| download | perlweeklychallenge-club-4e5a407712af3485999e3ad353019e7f6517c063.tar.gz perlweeklychallenge-club-4e5a407712af3485999e3ad353019e7f6517c063.tar.bz2 perlweeklychallenge-club-4e5a407712af3485999e3ad353019e7f6517c063.zip | |
Merge pull request #9381 from steve-g-lynn/branch-for-challenge-251
PWC 251
| -rw-r--r-- | challenge-251/steve-g-lynn/blog.txt | 1 | ||||
| -rw-r--r-- | challenge-251/steve-g-lynn/perl/ch-1.pl | 15 | ||||
| -rw-r--r-- | challenge-251/steve-g-lynn/perl/ch-2.pl | 48 | ||||
| -rw-r--r-- | challenge-251/steve-g-lynn/python/ch-1.py | 18 | ||||
| -rw-r--r-- | challenge-251/steve-g-lynn/python/ch-2.py | 23 |
5 files changed, 105 insertions, 0 deletions
diff --git a/challenge-251/steve-g-lynn/blog.txt b/challenge-251/steve-g-lynn/blog.txt new file mode 100644 index 0000000000..1088e03652 --- /dev/null +++ b/challenge-251/steve-g-lynn/blog.txt @@ -0,0 +1 @@ +https://thiujiac.blogspot.com/2024/01/pwc-251.html diff --git a/challenge-251/steve-g-lynn/perl/ch-1.pl b/challenge-251/steve-g-lynn/perl/ch-1.pl new file mode 100644 index 0000000000..fa2c073b20 --- /dev/null +++ b/challenge-251/steve-g-lynn/perl/ch-1.pl @@ -0,0 +1,15 @@ +# Perl 4.019 on DOSBOX
+
+sub concatenation_value {
+ local(@ints)=@_;
+ local($x,$retval)=(0,0);
+ foreach $x (0 .. @ints/2-1) {
+ $retval += $ints[$x] . $ints[$#ints-$x];
+ }
+ (@ints % 2) && ($retval += $ints[$#ints/2]);
+ return $retval;
+}
+
+print &concatenation_value( 6,12, 25, 1),"\n"; #1286
+print &concatenation_value( 10,7,31,5,2,2),"\n"; #489
+print &concatenation_value( 1,2,10),"\n"; #112
diff --git a/challenge-251/steve-g-lynn/perl/ch-2.pl b/challenge-251/steve-g-lynn/perl/ch-2.pl new file mode 100644 index 0000000000..dae91bf89e --- /dev/null +++ b/challenge-251/steve-g-lynn/perl/ch-2.pl @@ -0,0 +1,48 @@ +#perl 4.019 on DOSBOX
+
+sub matrix {
+ local ($nrow, $ncol, @data)=@_;
+ (scalar(@data)==$nrow*$ncol) || die "Matrix data input error: $!\n";
+
+ local (%matrix,$y,$x);
+ foreach $y (0 .. $nrow-1){
+ foreach $x (0 .. $ncol-1){
+ $matrix{ "$y,$x" } = shift(@data);
+ }
+ }
+ %matrix;
+}
+
+sub column {
+ local ($colno, %matrix)=@_;
+ local (@column) = @matrix { grep( $_ =~ /,$colno/, keys %matrix) };
+ @column;
+}
+
+sub row {
+ local ($rowno, %matrix)=@_;
+ local (@row) = @matrix { grep( $_ =~ /^$rowno,/, keys %matrix) };
+ @row;
+}
+
+sub lucky_numbers {
+ local ($nrow, $ncol)=($_[0], $_[1]);
+ local (%matrix)=&matrix(@_);
+ local ($y, $x,$retval);
+ $retval=-1;
+ OUTER: foreach $y (0 .. $nrow-1) {
+ INNER: foreach $x (0 .. $ncol-1) {
+ local ($rowmin)=((sort {$a<=>$b;} &row($y, %matrix))[0]);
+ local ($colmax)=((sort {$b<=>$a;} &column($x, %matrix))[0]);
+ if (($matrix{"$y,$x"}==$rowmin) && ($matrix{"$y,$x"}==$colmax)) {
+ $retval = $matrix{"$y,$x"};
+ last OUTER;
+ } #if
+ } #INNER
+ } #OUTER
+ $retval;
+}
+
+print &lucky_numbers(3,3,3,7,8,9,11,13,15,16,17),"\n"; #15
+print &lucky_numbers(3,4,1,10,4,2,9,3,8,7,15,16,17,12),"\n"; #12
+print &lucky_numbers(2,2,7,8,1,2),"\n"; #7
diff --git a/challenge-251/steve-g-lynn/python/ch-1.py b/challenge-251/steve-g-lynn/python/ch-1.py new file mode 100644 index 0000000000..cb6e65cf98 --- /dev/null +++ b/challenge-251/steve-g-lynn/python/ch-1.py @@ -0,0 +1,18 @@ +
+# Python 1.4 beta on DOSBOX
+
+import string
+
+def concatenation_value( ints ):
+ retval=0
+ for i in range(int(len(ints)/2)):
+ concat = str(ints[i])+str(ints[len(ints)-i-1])
+ retval = retval+string.atoi(concat)
+ if ((len(ints) % 2) ==1):
+ retval = retval + ints[ len(ints)/2 ]
+ return retval
+
+print concatenation_value( [6,12,25,1] ) #1286
+print concatenation_value( [10,7,31,5,2,2] ) #489
+print concatenation_value( [1,2,10] ) #112
+
diff --git a/challenge-251/steve-g-lynn/python/ch-2.py b/challenge-251/steve-g-lynn/python/ch-2.py new file mode 100644 index 0000000000..82190ef832 --- /dev/null +++ b/challenge-251/steve-g-lynn/python/ch-2.py @@ -0,0 +1,23 @@ +# python 1.4 beta on DOSBOX
+
+def column( inmatrix, colno ):
+ retval=[]
+ for y in range(len(inmatrix)):
+ retval.append( (inmatrix[y])[colno] )
+ return retval
+
+def lucky_numbers( inmatrix ):
+ retval=-1;
+ ncol=len(inmatrix[0])
+ nrow=len(inmatrix)
+ for y in range(nrow):
+ for x in range(ncol):
+ if (inmatrix[y])[x]==max(column(inmatrix,x)) == min(inmatrix[y]):
+ retval = (inmatrix[y])[x]
+ break
+ return retval
+
+print lucky_numbers( [[3,7,8],[9,11,13],[15,16,17]] ) #15
+print lucky_numbers( [[1,10,4,2],[9,3,8,7],[15,16,17,12]] ) #12
+print lucky_numbers( [[7,8],[1,2]] ) #7
+
|
