diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2019-06-26 17:17:27 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-06-26 17:17:27 +0100 |
| commit | f8eb67dfb5db0f2a45924bab9774df6197e2f98c (patch) | |
| tree | 4be14cb709484fe4a3e1ab93c4554495b961c763 /challenge-014/feng-chang | |
| parent | 7c04dd47b6278d9e14fc1b4aef7649308cf914bd (diff) | |
| parent | 365a21e5a71bd4db362173a597b0d970e6907ef8 (diff) | |
| download | perlweeklychallenge-club-f8eb67dfb5db0f2a45924bab9774df6197e2f98c.tar.gz perlweeklychallenge-club-f8eb67dfb5db0f2a45924bab9774df6197e2f98c.tar.bz2 perlweeklychallenge-club-f8eb67dfb5db0f2a45924bab9774df6197e2f98c.zip | |
Merge pull request #306 from seaker/mybranch
challeng 014
Diffstat (limited to 'challenge-014/feng-chang')
| -rwxr-xr-x | challenge-014/feng-chang/perl5/ch-1.pl | 22 | ||||
| -rwxr-xr-x | challenge-014/feng-chang/perl5/ch-2.pl | 40 | ||||
| -rwxr-xr-x | challenge-014/feng-chang/perl6/ch-1.p6 | 18 | ||||
| -rwxr-xr-x | challenge-014/feng-chang/perl6/ch-2.p6 | 17 |
4 files changed, 97 insertions, 0 deletions
diff --git a/challenge-014/feng-chang/perl5/ch-1.pl b/challenge-014/feng-chang/perl5/ch-1.pl new file mode 100755 index 0000000000..91815b7ad5 --- /dev/null +++ b/challenge-014/feng-chang/perl5/ch-1.pl @@ -0,0 +1,22 @@ +#!/bin/env perl + +use Modern::Perl; + +my @eck = (0, 0); + +exit unless defined $ARGV[0]; +my $n = int($ARGV[0]); +exit if $n < 2; + +for my $i (2 .. $n) { + $eck[$i] = 0; + + for (my $j = $i - 2; $j >= 0; --$j) { + if ($eck[$j] == $eck[$i - 1]) { + $eck[$i] = $i - $j - 1; + last; + } + } +} + +say join(' ', @eck); diff --git a/challenge-014/feng-chang/perl5/ch-2.pl b/challenge-014/feng-chang/perl5/ch-2.pl new file mode 100755 index 0000000000..74159cb8e0 --- /dev/null +++ b/challenge-014/feng-chang/perl5/ch-2.pl @@ -0,0 +1,40 @@ +#!/bin/env perl + +use Modern::Perl; + +my @aUSPS = qw( + al ak az ar ca co ct de fl ga + hi id il in ia ks ky la me md + ma mi mn ms mo mt ne nv nh nj + nm ny nc nd oh ok or pa ri sc + sd tn tx ut vt va wa wv wi wy +); + +my %hUSPS; +map { $hUSPS{ $_ } = 1 } @aUSPS; + +my @words; +my $max_len = 0; + +open my $fh, '<', '/usr/share/dict/words' or die "cannot read /usr/share/dict/words\n"; + +myloop: +while (my $w = <$fh>) { + chomp $w; + $w = lc($w); + + for my $p ($w =~ m/..?/g) { + next myloop unless $hUSPS{ $p }; + } + + push @words, $w; + my $len = length $w; + $max_len = $len if $len > $max_len; +} +close $fh; + +say "max word length is $max_len"; + +for my $w (@words) { + say $w if length($w) == $max_len; +} diff --git a/challenge-014/feng-chang/perl6/ch-1.p6 b/challenge-014/feng-chang/perl6/ch-1.p6 new file mode 100755 index 0000000000..7fe81fe8ea --- /dev/null +++ b/challenge-014/feng-chang/perl6/ch-1.p6 @@ -0,0 +1,18 @@ +#!/bin/env perl6 + +sub MAIN(UInt $n) { + my @eck = 0, 0; + + for 2..$n -> Int $i { + @eck[$i] = 0; + + for $i - 2 ... 0 -> Int $j { + if @eck[$j] == @eck[$i - 1] { + @eck[$i] = $i - $j - 1; + last; + } + } + } + + say @eck; +} diff --git a/challenge-014/feng-chang/perl6/ch-2.p6 b/challenge-014/feng-chang/perl6/ch-2.p6 new file mode 100755 index 0000000000..5c11db745a --- /dev/null +++ b/challenge-014/feng-chang/perl6/ch-2.p6 @@ -0,0 +1,17 @@ +#!/bin/env perl6 + +my @usps = < + al ak az ar ca co ct de fl ga + hi id il in ia ks ky la me md + ma mi mn ms mo mt ne nv nh nj + nm ny nc nd oh ok or pa ri sc + sd tn tx ut vt va wa wv wi wy +>; + +my @words = '/usr/share/dict/words'.IO.lines».lc.grep({ all($_.comb(2)) ∈ @usps }).unique; + +my Int $max-length = @words».chars.max; +say "max word length is $max-length"; + +my @longest-words = @words.grep: { $_.chars == $max-length }; +say @longest-words; |
