4 ms·
Haskell: maximumBy (on compare length) . filter ((< 3) . length . filter (`elem` "aeiou")) $ words phrase That returns "grasp", though, because it doesn't
by antonvs 3y 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.
- antonvs 3y agoPlus, 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
- leephillips 3y agoThe 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]`