aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorE7-87-83 <fungcheokyin@gmail.com>2021-05-03 23:07:07 +0800
committerE7-87-83 <fungcheokyin@gmail.com>2021-05-03 23:07:07 +0800
commit3d1a601a1bdb3d8b727c79361e2719d0fe0f5b96 (patch)
treef12038539fb6041874b96a400c46ddac022a4d50
parent0381a39b17ccd040302474f25d3c1cbbef703327 (diff)
downloadperlweeklychallenge-club-3d1a601a1bdb3d8b727c79361e2719d0fe0f5b96.tar.gz
perlweeklychallenge-club-3d1a601a1bdb3d8b727c79361e2719d0fe0f5b96.tar.bz2
perlweeklychallenge-club-3d1a601a1bdb3d8b727c79361e2719d0fe0f5b96.zip
early bird for week 111
-rw-r--r--challenge-110/cheok-yin-fung/java/TransposeFile.java2
-rw-r--r--challenge-111/cheok-yin-fung/perl/ch-1.pl34
-rw-r--r--challenge-111/cheok-yin-fung/perl/ch-2.pl51
3 files changed, 86 insertions, 1 deletions
diff --git a/challenge-110/cheok-yin-fung/java/TransposeFile.java b/challenge-110/cheok-yin-fung/java/TransposeFile.java
index 438d070b47..cbb9182f22 100644
--- a/challenge-110/cheok-yin-fung/java/TransposeFile.java
+++ b/challenge-110/cheok-yin-fung/java/TransposeFile.java
@@ -53,7 +53,7 @@ public class TransposeFile
System.out.println(e.getMessage());
System.exit(0);
} catch (IndexOutOfBoundsException e) {
- System.out.println("Usage: java Transpose [CSV file]");
+ System.out.println("Usage: java TransposeFile [CSV file]");
System.exit(0);
} catch (Exception e) {
System.out.println("Error(s) in input file.");
diff --git a/challenge-111/cheok-yin-fung/perl/ch-1.pl b/challenge-111/cheok-yin-fung/perl/ch-1.pl
new file mode 100644
index 0000000000..0797e1229d
--- /dev/null
+++ b/challenge-111/cheok-yin-fung/perl/ch-1.pl
@@ -0,0 +1,34 @@
+#!/usr/bin/perl
+# The Weekly Challenge 111
+# Task 1 Search Matrix
+use strict;
+use warnings;
+
+my $matrix=[[ 1, 2, 3, 5, 7 ],
+ [ 9, 11, 15, 19, 20 ],
+ [ 23, 24, 25, 29, 31 ],
+ [ 32, 33, 39, 40, 42 ],
+ [ 45, 47, 48, 49, 50 ]];
+
+my $target = $ARGV[0];
+
+my @list25;
+push @list25, $_->@* foreach (@{$matrix});
+
+my @my_seq = (12,6,3,2,1,1);
+my $h = shift @my_seq;
+
+for (my $i=0; $i < scalar @my_seq ;$i++) {
+ if ($target > $list25[$h]) {
+ $h += $my_seq[$i];
+ } elsif ($target < $list25[$h]) {
+ $h -= $my_seq[$i];
+ } elsif ($target == $list25[$h]) {
+ print "1\n";
+ exit;
+ }
+}
+
+print "0\n";
+
+
diff --git a/challenge-111/cheok-yin-fung/perl/ch-2.pl b/challenge-111/cheok-yin-fung/perl/ch-2.pl
new file mode 100644
index 0000000000..5b1bf68d49
--- /dev/null
+++ b/challenge-111/cheok-yin-fung/perl/ch-2.pl
@@ -0,0 +1,51 @@
+#!/usr/bin/perl
+# The Weekly Challenge 111
+# Ordered Letters
+# Default Word List:
+# http://www-personal.umich.edu/~jlawler/wordlist.html
+use strict;
+use warnings;
+
+my $dictfile;
+
+if ($ARGV[0]) {
+ $dictfile = $ARGV[0];
+}
+else {
+ $dictfile = "word_list";
+}
+
+open DICT, "<", $dictfile
+ or die "no such text file for the dictionary: $dictfile";
+
+my @max_club;
+my $max_len = 1;
+
+foreach my $w (<DICT>) {
+ chomp($w);
+ $w =~ s/\r//g;
+ if (length $w >= $max_len) { #only test those long words
+ my $w_ord = join "" , sort(split //, $w);
+ if ($w eq $w_ord) {
+ if ((length $w) > $max_len) {
+ update_max($w);
+ } else {
+ push @max_club, $w;
+ }
+ }
+ }
+}
+
+print join "\n", @max_club;
+print "\n";
+
+sub update_max {
+ @max_club = ($_[0]);
+ $max_len = length $_[0];
+}
+
+# result: aegilops, with length = 9
+
+# for most common 1000 English words:
+# accept, almost, effort, with length = 7
+