diff options
| author | Abigail <abigail@abigail.be> | 2021-05-03 17:40:10 +0200 |
|---|---|---|
| committer | Abigail <abigail@abigail.be> | 2021-05-03 17:40:10 +0200 |
| commit | 9dd85135a86d3baa87f1858f272a2a47efbfd159 (patch) | |
| tree | 737048fcd48abe9719026bd4eb6ebdd07a48dec5 /challenge-111 | |
| parent | 00a6aa4bd996590102bf471f77da0908f118bbe0 (diff) | |
| download | perlweeklychallenge-club-9dd85135a86d3baa87f1858f272a2a47efbfd159.tar.gz perlweeklychallenge-club-9dd85135a86d3baa87f1858f272a2a47efbfd159.tar.bz2 perlweeklychallenge-club-9dd85135a86d3baa87f1858f272a2a47efbfd159.zip | |
Perl solution for week 111, part 2
Diffstat (limited to 'challenge-111')
| -rw-r--r-- | challenge-111/abigail/README.md | 28 | ||||
| -rw-r--r-- | challenge-111/abigail/perl/ch-2.pl | 57 |
2 files changed, 84 insertions, 1 deletions
diff --git a/challenge-111/abigail/README.md b/challenge-111/abigail/README.md index def177b2a6..5f00924966 100644 --- a/challenge-111/abigail/README.md +++ b/challenge-111/abigail/README.md @@ -10,7 +10,6 @@ ### Notes - ### Solutions ### Blog @@ -24,7 +23,34 @@ > Write a script to find the longest English words that don't change when > their letters are sorted. +### Notes +We will grep the words from standard input which don't change +if they are sorted; these are the words which match the pattern +/^a*b*c*...z*$/i. We keep track of the longest word. + +If course, there does not have to be a unique word. It will depend +on the word list used to search in. For instance, three different +word list I used give different results: + + infochimps.com /usr/share/dict/words enable.lst + -------------- --------------------- ---------- + Adelops + aegilops + alloquy + beefily beefily + begorry + billowy billowy + egilops + +Only one of them has a unique longest word. + +We will be reading a word list from standard input, and write +the longest word where the letters are in alphabetical order +to standard output. In case of ties, we print the first one found. + + ### Solutions +* [Perl](perl/ch-2.pl) ### Blog diff --git a/challenge-111/abigail/perl/ch-2.pl b/challenge-111/abigail/perl/ch-2.pl new file mode 100644 index 0000000000..5f4041c69c --- /dev/null +++ b/challenge-111/abigail/perl/ch-2.pl @@ -0,0 +1,57 @@ +#!/opt/perl/bin/perl + +use 5.032; + +use strict; +use warnings; +no warnings 'syntax'; + +use experimental 'signatures'; +use experimental 'lexical_subs'; + +# +# See ../README.md +# + +# +# Run as: perl ch-2.pl < word-list +# + +# +# We will grep the words from standard input which don't change +# if they are sorted; these are the words which match the pattern +# /^a*b*c*...z*$/i. We keep track of the longest word. +# +# If course, there does not have to be a unique word. It will depend +# on the word list used to search in. For instance, three different +# word list I used give different results: +# +# infochimps.com /usr/share/dict/words enable.lst +# -------------- --------------------- ---------- +# Adelops +# aegilops +# alloquy +# beefily beefily +# begorry +# billowy billowy +# egilops +# +# Only one of them has a unique longest word. +# + +# +# We will be reading a word list from standard input, and write +# the longest word where the letters are in alphabetical order +# to standard output. In case of ties, we print the first one found. +# + + +my $pat = join "" => map {"$_*"} 'a' .. 'z'; + +my $longest = ""; + +while (<>) { + $longest = $_ if /^$pat$/i && length ($_) > length ($longest) +} + +print $longest; |
