aboutsummaryrefslogtreecommitdiff
path: root/challenge-256
diff options
context:
space:
mode:
authorStephen Lynn <bizlsg@localhost.localdomain>2024-02-12 20:25:55 +0800
committerStephen Lynn <bizlsg@localhost.localdomain>2024-02-12 20:25:55 +0800
commit15c4c540ac985cc5f1ad7cddcd40d11ac9e10c0e (patch)
treeffb713af0f3594abaa75b98341cb028e5b196aef /challenge-256
parent3f3e0798a68401ce1d67a5e1534f69de16856e82 (diff)
downloadperlweeklychallenge-club-15c4c540ac985cc5f1ad7cddcd40d11ac9e10c0e.tar.gz
perlweeklychallenge-club-15c4c540ac985cc5f1ad7cddcd40d11ac9e10c0e.tar.bz2
perlweeklychallenge-club-15c4c540ac985cc5f1ad7cddcd40d11ac9e10c0e.zip
pwc 256
Diffstat (limited to 'challenge-256')
-rw-r--r--challenge-256/steve-g-lynn/blog.txt1
-rw-r--r--challenge-256/steve-g-lynn/perl/ch-1.pl20
-rw-r--r--challenge-256/steve-g-lynn/perl/ch-2.pl18
-rw-r--r--challenge-256/steve-g-lynn/python/ch-1.py21
-rw-r--r--challenge-256/steve-g-lynn/python/ch-2.py17
5 files changed, 77 insertions, 0 deletions
diff --git a/challenge-256/steve-g-lynn/blog.txt b/challenge-256/steve-g-lynn/blog.txt
new file mode 100644
index 0000000000..9c37baeb0c
--- /dev/null
+++ b/challenge-256/steve-g-lynn/blog.txt
@@ -0,0 +1 @@
+https://thiujiac.blogspot.com/2024/02/pwc-256.html
diff --git a/challenge-256/steve-g-lynn/perl/ch-1.pl b/challenge-256/steve-g-lynn/perl/ch-1.pl
new file mode 100644
index 0000000000..01c195df13
--- /dev/null
+++ b/challenge-256/steve-g-lynn/perl/ch-1.pl
@@ -0,0 +1,20 @@
+# Perl 4.019 on DOSBOX
+
+sub maximum_pairs {
+ local(%seen,$count,$i);
+ $count=0;
+ for $i (@_){
+ if ( $seen{ reverse($i) } ) {
+ $count++;
+ $seen{ reverse($i) } = undef;
+ }
+ else {
+ $seen{$i}=1;
+ }
+ }
+ $count;
+}
+
+print &maximum_pairs("ab", "de", "ed", "bc"),"\n"; #1
+print &maximum_pairs("aa", "ba", "cd", "ed"),"\n"; #0
+print &maximum_pairs("uv", "qp", "st", "vu", "mn", "pq"),"\n"; #2
diff --git a/challenge-256/steve-g-lynn/perl/ch-2.pl b/challenge-256/steve-g-lynn/perl/ch-2.pl
new file mode 100644
index 0000000000..9458043015
--- /dev/null
+++ b/challenge-256/steve-g-lynn/perl/ch-2.pl
@@ -0,0 +1,18 @@
+#perl 4.019 on DOSBOX
+
+sub merge_strings {
+ local( @str1 ) = split(//,$_[0]);
+ local( @str2 ) = split(//,$_[1]);
+ local($max_len)= (($#str1 > $#str2) ? $#str1 : $#str2);
+ local( @retval )=();
+ local( $i );
+ foreach $i (0 .. ($max_len)){
+ defined($str1[$i]) && push( @retval, $str1[$i] ) ;
+ defined($str2[$i]) && push( @retval, $str2[$i] ) ;
+ }
+ join( "", @retval);
+}
+
+print &merge_strings("abcd","1234"),"\n"; #a1b2c3d4
+print &merge_strings("abc","12345"),"\n"; #a1b2c345
+print &merge_strings("abcde","123"),"\n"; #a1b2c3de
diff --git a/challenge-256/steve-g-lynn/python/ch-1.py b/challenge-256/steve-g-lynn/python/ch-1.py
new file mode 100644
index 0000000000..39dddba57b
--- /dev/null
+++ b/challenge-256/steve-g-lynn/python/ch-1.py
@@ -0,0 +1,21 @@
+# Python 1.4 beta on DOSBOX
+
+import string
+
+def maximum_pairs( words ):
+ seen={}
+ count=0
+ for i in words:
+ rev_i=list(str(i))
+ rev_i.reverse()
+ rev_i=string.joinfields( rev_i, "" )
+ if seen.has_key(rev_i) and seen[rev_i]==1:
+ count=count+1
+ seen[rev_i]=0
+ else:
+ seen[i]=1
+ return count
+
+print maximum_pairs( ["ab", "de", "ed", "bc" ] ) #1
+print maximum_pairs( ["aa", "ba", "cd", "ed" ] ) #0
+print maximum_pairs( ["uv", "qp", "st", "vu", "mn", "pq"] ) #2
diff --git a/challenge-256/steve-g-lynn/python/ch-2.py b/challenge-256/steve-g-lynn/python/ch-2.py
new file mode 100644
index 0000000000..fa6f620242
--- /dev/null
+++ b/challenge-256/steve-g-lynn/python/ch-2.py
@@ -0,0 +1,17 @@
+# python 1.4 beta on DOSBOX
+
+import string
+
+def merge_strings( str1, str2 ):
+ max_len=max( len(str1), len(str2) )
+ retval=[]
+ for i in range(max_len):
+ if (len(str1) > i):
+ retval.append( str1[i] )
+ if (len(str2) > i):
+ retval.append( str2[i] )
+ return string.joinfields(retval,"")
+
+print merge_strings("abcd","1234") # a1b2c3d4
+print merge_strings("abc","12345") # a1b2c345
+print merge_strings("abcde","123") # a1b2c3de