I have written the following code in Python 2.7
class BinaryCode:
def decode(self, message):
result = str(0)
result += str(message[0])
for i in range(1, len(message)-1):
result += str(int(message[i])-int(result[i])-int(result[i-1]))
return result
When I initialise message as 123210122, I want the result to be 011100011 but instead it's {"0", "1", "1", "1", "0", "0", "0", "1", "1"}. How to do this?
This is a topcoder SRM 144 Div 2 problem and this was the result.
Now, when I run this code in IDLE it gives me a string but then why its not working in topcoder?
Just change last line of function to
return ''.join(result)
.