Using the language of your choice write a program which inpu
Using the language of your choice, write a program which inputs a string of 1s and 0s and compresses the 0s using the run-length compression technique.
Solution
def rlEncode(input):
result = \'\'
if len(input) > 0:
index = 0
for value in input :
if value == \'0\':
break;
result+=value
index+=1
previous = input[index]
result+=previous
count = 1
for value in input[index+1:]:
print \"Value:\" + str(value)
if value == \'1\':
if count > 0:
result+=str(count)
previous = value
count = 0
result+=value
elif value == \'0\' and value != previous:
result+=value
previous = value
count+=1
elif value == previous :
previous = value
count += 1
else :
print \"Previous: \",previous
print \"Count:\",count
result+=str(count)
result+=value
previous = value
count = 1
result+=str(count)
return result
if __name__ == \"__main__\":
input = \'10111110000\'
rlEncodedList = rlEncode(input)
print \"Encoded string:\",rlEncodedList
