in reply to Find the shortest word in the English Language with: a b c d e f
The empty diamond with @ARGV lets (edit: not "let's") you win a few chars:
Using the magic increment on a string (eg 'a'), you can have /$a/ search for the successive letters in the alphabet (also "push if" is shorter than "next unless; push"):open$:,"</usr/share/dict/words";while(<$:>){...} @ARGV="/usr/share/dict/words";while(<>){...}
$a='a';$a++while/$a/;push@_,$_ if$a gt'f' next unless/(?=.*a)(?=.*b)(?=.*c)(?=.*d)(?=.*e)(?=.*f)/i;push@_,$_
And I thought the sorting was too verbose, so I stored the matching words by length to begin with:
That's 31 fewer chars than your version, not counting the extra ' in your perl code ;-)@ARGV="/usr/share/dict/words";while(<>){$a='a';$a++while/$a/i;push@{$_ +[length]},$_ if$a gt'f'}@_=map{$_?@$_:()}@_ open$:,"</usr/share/dict/words";while(<$:>){next unless/(?=.*a)(?=.*b) +(?=.*c)(?=.*d)(?=.*e)(?=.*f)/i;push@_,$_}@_=sort{length$a<=>length$b} +@_
A chomp might be needed somewhere though, adding at least 5 chars.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Find the shortest word in the English Language with: a b c d e f
by jwkrahn (Abbot) on Jul 04, 2018 at 18:51 UTC | |
by Eily (Monsignor) on Jul 05, 2018 at 08:22 UTC | |
by mr_mischief (Monsignor) on Jul 06, 2018 at 18:02 UTC | |
by Eily (Monsignor) on Jul 07, 2018 at 07:52 UTC | |
by shmem (Chancellor) on Jul 10, 2018 at 16:58 UTC | |
by tybalt89 (Monsignor) on Jul 11, 2018 at 15:45 UTC | |
|