diff options
Diffstat (limited to '6-kyu/duplicate-encoder.hs')
| -rw-r--r-- | 6-kyu/duplicate-encoder.hs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/6-kyu/duplicate-encoder.hs b/6-kyu/duplicate-encoder.hs new file mode 100644 index 0000000..1cb38eb --- /dev/null +++ b/6-kyu/duplicate-encoder.hs @@ -0,0 +1,18 @@ +-- https://www.codewars.com/kata/54b42f9314d9229fd6000d9c + +module Dups where + +import Data.Char + +count s c + | s == [] = 0 + | c == (head s) = 1 + count (tail s) c + | otherwise = count (tail s) c + +convert s c + | count s c > 1 = ')' + | otherwise = '(' + +duplicateEncode :: String -> String +duplicateEncode s = map (convert ls) ls + where ls = map toLower s |
