aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2022-04-21 16:33:04 +0100
committerGitHub <noreply@github.com>2022-04-21 16:33:04 +0100
commit9bf6c9cf4433f447edd548049d583eeca3a0d2ed (patch)
tree74dcc53d83c86cf950ef590e49a5761c53adb092
parent0d021cf08d9012cdb13e7ddbf3146d7d08a2431f (diff)
parente9dcdecd99edb78db01d5b81e4a9f3a1c527ae1b (diff)
downloadperlweeklychallenge-club-9bf6c9cf4433f447edd548049d583eeca3a0d2ed.tar.gz
perlweeklychallenge-club-9bf6c9cf4433f447edd548049d583eeca3a0d2ed.tar.bz2
perlweeklychallenge-club-9bf6c9cf4433f447edd548049d583eeca3a0d2ed.zip
Merge pull request #5973 from pokgopun/pwc161
pwc161 refactor perl solution, go solution to accept argument as path…
-rw-r--r--challenge-161/pokgopun/go/ch-1.go6
-rw-r--r--challenge-161/pokgopun/go/ch-2.go6
-rw-r--r--challenge-161/pokgopun/perl/ch-1.pl21
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;
+}