diff options
| author | Michael Lee Firkins <michael@firkins> | 2022-04-21 09:35:56 +0700 |
|---|---|---|
| committer | Michael Lee Firkins <michael@firkins> | 2022-04-21 10:37:00 +0700 |
| commit | e9dcdecd99edb78db01d5b81e4a9f3a1c527ae1b (patch) | |
| tree | 74dcc53d83c86cf950ef590e49a5761c53adb092 | |
| parent | 0d021cf08d9012cdb13e7ddbf3146d7d08a2431f (diff) | |
| download | perlweeklychallenge-club-e9dcdecd99edb78db01d5b81e4a9f3a1c527ae1b.tar.gz perlweeklychallenge-club-e9dcdecd99edb78db01d5b81e4a9f3a1c527ae1b.tar.bz2 perlweeklychallenge-club-e9dcdecd99edb78db01d5b81e4a9f3a1c527ae1b.zip | |
pwc161 refactor perl solution, go solution to accept argument as path input file
| -rw-r--r-- | challenge-161/pokgopun/go/ch-1.go | 6 | ||||
| -rw-r--r-- | challenge-161/pokgopun/go/ch-2.go | 6 | ||||
| -rw-r--r-- | challenge-161/pokgopun/perl/ch-1.pl | 21 |
3 files changed, 21 insertions, 12 deletions
diff --git a/challenge-161/pokgopun/go/ch-1.go b/challenge-161/pokgopun/go/ch-1.go index 9e15a8cf09..863f6cbd05 100644 --- a/challenge-161/pokgopun/go/ch-1.go +++ b/challenge-161/pokgopun/go/ch-1.go @@ -9,7 +9,11 @@ import ( ) func main() { - f, err := os.Open("../../../data/dictionary.txt") + dict := "../../../data/dictionary.txt" + if len(os.Args) > 1 { + dict = os.Args[1] + } + f, err := os.Open(dict) if err != nil { log.Fatal(err) } diff --git a/challenge-161/pokgopun/go/ch-2.go b/challenge-161/pokgopun/go/ch-2.go index 28ccb9f249..07fee3a83c 100644 --- a/challenge-161/pokgopun/go/ch-2.go +++ b/challenge-161/pokgopun/go/ch-2.go @@ -31,7 +31,11 @@ func (bs byteSeen) countUnseen(s string) (n int) { return n } func main() { - f, err := os.Open("../../../data/dictionary.txt") + dict := "../../../data/dictionary.txt" + if len(os.Args) > 1 { + dict = os.Args[1] + } + f, err := os.Open(dict) if err != nil { log.Fatal(err) } diff --git a/challenge-161/pokgopun/perl/ch-1.pl b/challenge-161/pokgopun/perl/ch-1.pl index f792a41e4d..567b05f850 100644 --- a/challenge-161/pokgopun/perl/ch-1.pl +++ b/challenge-161/pokgopun/perl/ch-1.pl @@ -2,6 +2,7 @@ use strict; use warnings; my $dict = @ARGV ? shift : "../../../data/dictionary.txt"; +printf "%s\n", join(", ",abc($dict)); sub abc{ my $dict = shift; @@ -12,20 +13,20 @@ sub abc{ my @abc; while (my $line = ref $IN eq 'GLOB' ? <$IN> : shift @$IN){ chomp $line; - my @a = split //,$line; - my @b; - { - push @b, shift @a; - last unless @a; - last if $b[-1] gt $a[0]; - redo; - } - push @abc,$line if length($line)==@b; + push @abc,$line if isAbc($line); } @abc = sort{ length $b <=> length $a} @abc unless ref $IN eq 'ARRAY'; return @abc } -printf "%s\n", join(", ",abc($dict)); +sub isAbc{ + my @a = split //, shift; + if (@a > 1) { + for (my $i = 1; $i < @a; $i++){ + return 0 if $a[$i] lt $a[$i-1]; + } + } + return 1; +} |
