summaryrefslogtreecommitdiff
path: root/6-kyu/duplicate-encoder.hs
diff options
context:
space:
mode:
authorMistivia <i@mistivia.com>2025-04-24 02:46:39 +0800
committerMistivia <i@mistivia.com>2025-04-24 02:46:39 +0800
commit2a9e59907868d12a2a3ea387ec90074e26cc90c3 (patch)
tree8bc367c09ab4e1967481fd97abf1e29a81f62b04 /6-kyu/duplicate-encoder.hs
init
Diffstat (limited to '6-kyu/duplicate-encoder.hs')
-rw-r--r--6-kyu/duplicate-encoder.hs18
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