diff options
author | thing1 <thing1@seacrossedlovers.xyz> | 2025-04-03 08:33:24 +0000 |
---|---|---|
committer | thing1 <thing1@seacrossedlovers.xyz> | 2025-04-03 08:33:24 +0000 |
commit | 32b9a010a24570a131cc5c9521b8e76102e9cd38 (patch) | |
tree | f2ed30747f8259fd082010165aa349ee6509c8b9 | |
parent | f5d3ee099170e1a3812923172fa1c77049d83abf (diff) |
made a very cool run length encoding algorithum
-rw-r--r-- | comp/work/55/rle.py | 30 | ||||
-rw-r--r-- | comp/work/55/starter | 1 |
2 files changed, 31 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"))) + diff --git a/comp/work/55/starter b/comp/work/55/starter new file mode 100644 index 0000000..88bfc18 --- /dev/null +++ b/comp/work/55/starter @@ -0,0 +1 @@ +A flip flop stores the value placed into it, until the clock pulses, where it then re reads from input D, it is always outputting on output Q
\ No newline at end of file |