diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2022-04-24 22:05:28 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-04-24 22:05:28 +0100 |
| commit | 990946b9ba4338c548e92446ce652d7d99e92caa (patch) | |
| tree | cd735cf52b78300e47af206b41d6ddd7d86299a7 | |
| parent | ed855f5135326b1c01e9cc36acd079b72b849387 (diff) | |
| parent | f2f92d1a343d8078dc0079a406177410f7ae69fd (diff) | |
| download | perlweeklychallenge-club-990946b9ba4338c548e92446ce652d7d99e92caa.tar.gz perlweeklychallenge-club-990946b9ba4338c548e92446ce652d7d99e92caa.tar.bz2 perlweeklychallenge-club-990946b9ba4338c548e92446ce652d7d99e92caa.zip | |
Merge pull request #5994 from PerlBoy1967/branch-for-challenge-161
Task #1 (not enough time this week for #2)
| -rwxr-xr-x | challenge-161/perlboy1967/perl/ch-1.pl | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/challenge-161/perlboy1967/perl/ch-1.pl b/challenge-161/perlboy1967/perl/ch-1.pl new file mode 100755 index 0000000000..d22b705cd6 --- /dev/null +++ b/challenge-161/perlboy1967/perl/ch-1.pl @@ -0,0 +1,42 @@ +#!/bin/perl + +=pod + +The Weekly Challenge - 161 + - https://perlweeklychallenge.org/blog/perl-weekly-challenge-161/#TASK1 + +Author: Niels 'PerlBoy' van Dijke + +Task 1: Abecedarian Words +Submitted by: Ryan J Thompson + +An abecedarian word is a word whose letters are arranged in alphabetical order. +For example, “knotty” is an abecedarian word, but “knots” is not. Output or +return a list of all abecedarian words in the dictionary, sorted in decreasing +order of length. + +Optionally, using only abecedarian words, leave a short comment in your code +to make your reviewer smile. + +=cut + +use v5.16; + +my $dictFile = shift // '../../../data/dictionary.txt'; + +open(my $fhDict, '<', $dictFile) || + die "Can't open dictfile '$dictFile' ($!)"; + +my %w; +while (<$fhDict>) { + chomp; + if ($_ eq join '',sort split //) { + push(@{$w{length $_}},$_); + } +} +close($fhDict); + +say join("\n",map {join("\n", reverse sort @{$w{$_}})} sort {$b<=>$a} keys %w); + +__END__ +Abecedarian quote for Colin: A hot dirty messy hippy chills at empty glossy films |
