summaryrefslogtreecommitdiff
path: root/comp/work/55/rle.py
diff options
context:
space:
mode:
Diffstat (limited to 'comp/work/55/rle.py')
-rw-r--r--comp/work/55/rle.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/comp/work/55/rle.py b/comp/work/55/rle.py
new file mode 100644
index 0000000..c2c43da
--- /dev/null
+++ b/comp/work/55/rle.py
@@ -0,0 +1,30 @@
+def rle(s):
+ en = ""
+ c = s[0]
+ cc = 0
+ for i in s:
+ if i == c: cc += 1
+ else:
+ en += (c if (cc == 1) else str(cc) + c)
+ c = i
+ cc = 1
+ en += (c if (cc == 1) else str(cc) + c)
+ return en
+
+def rld(s):
+ de = ""
+ cc = ""
+ c = ''
+ for i in s:
+ if i.isdigit(): cc += i
+ else:
+ c = i
+ if not cc.isdigit(): cc = "1"
+ de += c * int(cc)
+ cc = ""
+
+ return de
+
+
+print(rld(rle("abbbcccd")))
+