praxis

Various programming exercises.
Log | Files | Refs

commit ffa3f667065c59116f2e21f9e69cf5158c055001
parent 0ee3cac16b00e454bdd54cf3bcd4b34aa4c57c5f
Author: Jared Tobin <jared@jtobin.ca>
Date:   Fri, 13 Jul 2018 22:10:37 +1200

Add hacky find & replace.

Diffstat:
A20180713_laundry/Laundry.hs | 26++++++++++++++++++++++++++
1 file changed, 26 insertions(+), 0 deletions(-)

diff --git a/20180713_laundry/Laundry.hs b/20180713_laundry/Laundry.hs @@ -0,0 +1,26 @@ +{-# OPTIONS_GHC -Wall -fno-warn-type-defaults #-} + +test :: String +test = + mconcat [ + "ABCDE This is some text.", "\n" + , "This is more text. ABCDE, ABCDE.", "\n" + , "ABCDE And this is [ABCDE] still more text." + ] + +fnr :: String -> String +fnr = loop 1 mempty where + loop j acc input = case input of + [] -> reverse acc + ('A':t) -> + if match input + then + let label = show j ++ "X" + in loop (succ j) (label ++ acc) (drop 5 input) + else + loop j ('A':acc) t + + (h:t) -> loop j (h:acc) t + +match :: String -> Bool +match input = take 5 input == "ABCDE"