Advertisement
Guest User

Loose Emilia

a guest
Jun 6th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import Data.List     as L
  2. import Data.Sequence as Q
  3.  
  4. data Bird = Azure | Black | Carmine
  5.  
  6. main = interact $ unlines . map (show . Q.length) . L.filter onlyAzure .
  7.                   L.unfoldr bellRing . flip Q.replicate Azure . read
  8.  
  9. bellRing Empty = Nothing
  10. bellRing w@(first :<| w') = Just (w,w''') where
  11.   w''' = case w' of _ :<| w'' -> w'' >< endOfLine
  12.                     Empty -> empty -- I HATE YOU STUPID EDGE CASE
  13.   endOfLine = case first of Azure -> fromList [Black,Carmine]
  14.                             Black -> singleton Azure
  15.                             Carmine -> Q.replicate 3 Azure
  16.  
  17. onlyAzure w | Azure :<| _ <- w, _ :|> Azure <- w = True
  18. onlyAzure _ = False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement