|Keep It Simple, Stupid|
Re: Find the shortest word in the English Language with: a b c d e fby mr_mischief (Monsignor)
|on Jul 06, 2018 at 00:25 UTC||Need Help??|
For golf purposes, the data usually isn't embedded in the code. Here's a not-too golfed 116 characters that is flexible enough to have you specify your dictionary file as the first argument.
If we know already that we're looking for something shorter than ten characters, we can save one character right off the bat.$s=9;
But wait, we're storing an array just to take a count of its elements later. We also know there's just the one newline after the word, so chomp wastes one. We can save some strokes there, too. 110:
Speaking of storing things and referring to them later... 104:
Sometimes you can drop characters by switching your control flow a bit. 103:
Sometimes you can remove an operation by thinking a bit differently about your data. 101:
All of this, mind you, meets the exact spec of finding the shortest word rather than printing a sorted list of words. It's from scratch against that spec rather than deriving from the other solutions already presented. This is just a stab at describing the process of golfing down a solution that came to me from reading the spec. Notice I dropped 15 characters in 5 revisions from something that already had no whitespace, and this solution doesn't abuse the language too badly considering it's code golf. I'm sure someone can come along with some dirtier tricks and more magical parts of the language and get a shorter pure Perl solution.