Hacker News new | ask | show | jobs
by antonvs 841 days ago
Haskell:

    maximumBy (on compare length) . filter ((< 3) . length . filter (`elem` "aeiou")) $ words phrase
That returns "grasp", though, because it doesn't sort the list.
2 comments

The problem as stated does not have a unique solution in general, as you’ve found. One Julia program for this is

`sort(split(p)[count.(r"[aeiou]", split(p)) .< 3]; by=r -> length(r))[end]`

which also returns "grasp".

But this one appeals to me more, because it doesn’t split twice:

`sort(filter(w -> count(r"[aeiou]", w) < 3, split(p)); by=r -> length(r))[end]`

Plus, defining a few aliases for the punctuation-happy terseness-lovers among us, we can reduce the above to:

    maxBy(on cmp (#)).(((<3).(#).(el"aeiou"|=))|=)$words phrase