Created
April 9, 2020 11:45
-
-
Save workflow/fdaea441983483b51efa5a16747a706e to your computer and use it in GitHub Desktop.
Vowel Align in one line of Haskell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Applicative (liftA2) | |
import Data.List (maximumBy) | |
import Data.Ord (comparing) | |
vowAlign = let as = (map concat) . sequenceA . map ((\c -> [c, c ++ "#", "#" ++ c]) . pure) in (maximumBy ((comparing (\(_,_,x) -> x)) <> flip (comparing $ length . (\(_,x,_) -> x)) <> flip (comparing $ length . (\(x,_,_) -> x))).) . (map (\(s, s') -> (s, s', ((.) (foldr (\(c, c') acc -> if all ((flip elem) "AEIOU") $ [c] ++ [c'] then (acc + 1) else acc) 0) . zip) s s')).) . (.as) . liftA2 (,) . as | |
-- Acceptance tests | |
main :: IO () | |
main = | |
let x = "LAUFEN" | |
y = "ETUI" | |
x' = "FSSU" | |
y' = "BALL" in do | |
putStrLn $ show $ vowAlign x y | |
putStrLn $ show $ vowAlign x' y' |
Author
workflow
commented
Apr 9, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment