Skip to content

Instantly share code, notes, and snippets.

@futureimperfect
Last active July 27, 2016 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save futureimperfect/285a974c5448c3032ce3218a81f68136 to your computer and use it in GitHub Desktop.
Save futureimperfect/285a974c5448c3032ce3218a81f68136 to your computer and use it in GitHub Desktop.
def weird_encoding(s):
assert(isinstance(s, str))
first = list(s[::-1])
for i, c in enumerate(s):
if c.isupper():
first[i] = first[i].upper()
elif c.islower():
first[i] = first[i].lower()
first = ''.join(first)
second = str(len(s))
tmp = ''
for c in s:
if c.isdigit():
tmp += str(int(c) + 1)
continue
elif c in ('z', 'Z'):
tmp += 'a'
continue
tmp += chr(ord(c) + 1)
if s.isdigit():
third = tmp[::-1]
elif s[-1].isupper():
third = tmp.lower()[::-1]
else:
third = tmp.upper()[::-1]
return first + second + third
if __name__ == '__main__':
print(weird_encoding('Hello'))
print(weird_encoding('LoL'))
print(weird_encoding('123'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment