diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-05-04 19:34:52 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-05-04 19:34:52 +0100 |
| commit | 9275c6e70e8015230b388f5f03a08347218c432c (patch) | |
| tree | 79d5d5ce760b89d7891afc5dbe43871c84505b4c | |
| parent | c554ee9e4f28d6f9d7042e39d974932600d56679 (diff) | |
| parent | b023bdb4bd931fc3b42047a65f3431eeaf7e1e76 (diff) | |
| download | perlweeklychallenge-club-9275c6e70e8015230b388f5f03a08347218c432c.tar.gz perlweeklychallenge-club-9275c6e70e8015230b388f5f03a08347218c432c.tar.bz2 perlweeklychallenge-club-9275c6e70e8015230b388f5f03a08347218c432c.zip | |
Merge pull request #4011 from E7-87-83/newt
early bird for week 111
| -rw-r--r-- | challenge-110/cheok-yin-fung/java/TransposeFile.java | 2 | ||||
| -rw-r--r-- | challenge-111/cheok-yin-fung/perl/ch-1.pl | 35 | ||||
| -rw-r--r-- | challenge-111/cheok-yin-fung/perl/ch-2.pl | 51 |
3 files changed, 87 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..15dbe1ef59 --- /dev/null +++ b/challenge-111/cheok-yin-fung/perl/ch-1.pl @@ -0,0 +1,35 @@ +#!/usr/bin/perl +# The Weekly Challenge 111 +# Task 1 Search Matrix +# Usage: ch-1.pl [number looking for] +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]; + } else { # $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..2113667993 --- /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 = 6 + |
