Skip to content

Instantly share code, notes, and snippets.

@domarps
Created August 19, 2018 18:05
Show Gist options
  • Save domarps/4b74333c83266ddfacf1b7ab5792e902 to your computer and use it in GitHub Desktop.
Save domarps/4b74333c83266ddfacf1b7ab5792e902 to your computer and use it in GitHub Desktop.
TautDefiantGraduate created by domarps - https://repl.it/@domarps/TautDefiantGraduate
from random import choice
import string
def compress_string(s):
if len(s) < 3:
return 0
max_len = len(s) - 2
str_list = []
for num in range(len(s), 2, -1):
for i in range(1, len(s) - num):
str_list.append(s[0:i] + str(num) + s[i+num+1:])
return len(str_list)
results = []
for n in range(100):
input = ''.join([choice(string.ascii_letters) for j in range(n)])
result = compress_string(input)
results.append(result)
print(results)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment