Skip to content

Instantly share code, notes, and snippets.

@workflow
Created April 9, 2020 11:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save workflow/fdaea441983483b51efa5a16747a706e to your computer and use it in GitHub Desktop.
Save workflow/fdaea441983483b51efa5a16747a706e to your computer and use it in GitHub Desktop.
Vowel Align in one line of Haskell
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'
@workflow
Copy link
Author

workflow commented Apr 9, 2020

*Main> main
("LA#UFEN","#ETU#I",3)
("FSSU","#B#ALL",1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment