fork download
  1. import Data.Maybe
  2. import Data.List
  3. import Data.Ratio
  4.  
  5. first' "" _ = Just 0
  6. first' _ "" = Nothing
  7. first' (x:xs) ys = let
  8. (zs,ws) = break (==x) ys
  9. in if ws == ""
  10. then Nothing
  11. else ((length zs)+) <$> (first' xs $ tail ws)
  12.  
  13. first x y = fromMaybe 0 $ (negate.(1%).(+1)) <$> first' x y
  14.  
  15. trickOrTreat x = case compare (first "trick" x) (first "treat" x) of
  16. LT -> "trick"
  17. GT -> "treat"
  18. otherwise -> "Happy Halloween"
  19.  
  20. main = mapM_ (print.trickOrTreat) ["trick or treat", ". tr ick","ttrriecatk","tri kc eat","my money"]
  21.  
Success #stdin #stdout 0s 4572KB
stdin
Standard input is empty
stdout
"trick"
"trick"
"treat"
"treat"
"Happy Halloween"