diff options
| -rw-r--r-- | challenge-255/steve-g-lynn/blog.txt | 1 | ||||
| -rw-r--r-- | challenge-255/steve-g-lynn/perl/ch-1.pl | 25 | ||||
| -rw-r--r-- | challenge-255/steve-g-lynn/perl/ch-2.pl | 14 | ||||
| -rw-r--r-- | challenge-255/steve-g-lynn/python/ch-1.py | 26 | ||||
| -rw-r--r-- | challenge-255/steve-g-lynn/python/ch-2.py | 23 |
5 files changed, 89 insertions, 0 deletions
diff --git a/challenge-255/steve-g-lynn/blog.txt b/challenge-255/steve-g-lynn/blog.txt new file mode 100644 index 0000000000..dec5d606f7 --- /dev/null +++ b/challenge-255/steve-g-lynn/blog.txt @@ -0,0 +1 @@ +https://thiujiac.blogspot.com/2024/02/pwc-255.html diff --git a/challenge-255/steve-g-lynn/perl/ch-1.pl b/challenge-255/steve-g-lynn/perl/ch-1.pl new file mode 100644 index 0000000000..f643b16f54 --- /dev/null +++ b/challenge-255/steve-g-lynn/perl/ch-1.pl @@ -0,0 +1,25 @@ +# Perl 4.019 on DOSBOX
+
+sub odd_character {
+ local($s,$t)=@_;
+
+ #I leave out input validation chores.
+ #We assume that $t is a jumbled version of $s
+ #plus one extra character
+ #that we have to find and return
+ local(%s,%t,$i);
+ foreach $i (split(//,$s)) {
+ $s{$i}++;
+ }
+ foreach $i (split(//,$t)) {
+ $t{$i}++;
+ }
+ foreach $i (keys %t) {
+ ($t{$i} > $s{$i}) && (return $i);
+ }
+ return "ERROR";
+}
+
+print &odd_character("Perl","Preel"),"\n"; #e
+print &odd_character("Weekly","Weeakly"),"\n"; #a
+print &odd_character("Box","Boxy"),"\n"; #y
diff --git a/challenge-255/steve-g-lynn/perl/ch-2.pl b/challenge-255/steve-g-lynn/perl/ch-2.pl new file mode 100644 index 0000000000..ef910cf8a8 --- /dev/null +++ b/challenge-255/steve-g-lynn/perl/ch-2.pl @@ -0,0 +1,14 @@ +#perl 4.019 on DOSBOX
+
+sub most_frequent_word {
+ local( $p, $w )=@_;
+ local( @p ) = split(/[\s,.!?]+/,$p);
+ local( %p, $i );
+ foreach $i (@p) {
+ $p{$i}++ unless ($i eq $w);
+ }
+ (sort {$p{$b}<=>$p{$a};} keys %p)[0];
+}
+
+print &most_frequent_word("Joe hit a ball, the hit ball flew far after it was hit", "hit"),"\n"; #ball
+print &most_frequent_word("Perl and Raku belong to the same family. Perl is the most popular language in the weekly challenge.", "the"),"\n"; #Perl
diff --git a/challenge-255/steve-g-lynn/python/ch-1.py b/challenge-255/steve-g-lynn/python/ch-1.py new file mode 100644 index 0000000000..19bb6e9587 --- /dev/null +++ b/challenge-255/steve-g-lynn/python/ch-1.py @@ -0,0 +1,26 @@ +
+# Python 1.4 beta on DOSBOX
+
+def odd_character( s, t ):
+ in_s={}
+ in_t={}
+ for i in s:
+ try:
+ in_s[i] = in_s[i]+1
+ except KeyError:
+ in_s[i] = 1
+ for i in t:
+ try:
+ in_t[i] = in_t[i]+1
+ except KeyError:
+ in_t[i] = 1
+ for i in in_t.keys():
+ if not i in in_s.keys():
+ return i
+ if in_t[i] > in_s[i]:
+ return i
+ return "ERROR"
+
+print odd_character("Perl","Preel") #e
+print odd_character("Weekly","Weeakly") #a
+print odd_character("Box","Boxy") #y
diff --git a/challenge-255/steve-g-lynn/python/ch-2.py b/challenge-255/steve-g-lynn/python/ch-2.py new file mode 100644 index 0000000000..a0eff3661e --- /dev/null +++ b/challenge-255/steve-g-lynn/python/ch-2.py @@ -0,0 +1,23 @@ +# python 1.4 beta on DOSBOX
+# (does not work on python 2 or later)
+
+import string,regex,regsub
+
+def most_frequent_word( p, w ):
+ punct=regex.compile("[,.!?]")
+ p_nopunct=regsub.gsub(punct," ",p)
+ in_p={}
+ p_words=string.split(p_nopunct)
+ for word in p_words:
+ if not word==w:
+ try:
+ in_p[word]=in_p[word]+1
+ except KeyError:
+ in_p[word]=1
+ mymax=max(in_p.values())
+ for word in in_p.keys():
+ if (in_p[word]==mymax):
+ return word
+ return "ERROR!"
+print most_frequent_word("Joe hit a ball, the hit ball flew far after it was hit hit", "hit") #ball
+print most_frequent_word("Perl and Raku belong to the same family. Perl is the most popular language in the weekly challenge.","the") #Perl
|
