praxis

Various programming exercises.
git clone git://git.jtobin.io/praxis.git
Log | Files | Refs

Laundry.hs (615B)


      1 {-# OPTIONS_GHC -Wall -fno-warn-type-defaults #-}
      2 
      3 test :: String
      4 test =
      5   mconcat [
      6       "ABCDE This is some text.", "\n"
      7     , "This is more text. ABCDE, ABCDE.", "\n"
      8     , "ABCDE And this is [ABCDE] still more text."
      9     ]
     10 
     11 fnr :: String -> String
     12 fnr = loop 1 mempty where
     13   loop j acc input = case input of
     14     []      -> reverse acc
     15     ('A':t) ->
     16       if    match input
     17       then
     18         let label = show j ++ "X"
     19         in  loop (succ j) (label ++ acc) (drop 5 input)
     20       else
     21         loop j ('A':acc) t
     22 
     23     (h:t)   -> loop j (h:acc) t
     24 
     25 match :: String -> Bool
     26 match input = take 5 input == "ABCDE"