Skip to content

Instantly share code, notes, and snippets.

@theabbie
Created April 10, 2022 07:47
Show Gist options
  • Save theabbie/4808350d51053fdc33242353116652a6 to your computer and use it in GitHub Desktop.
Save theabbie/4808350d51053fdc33242353116652a6 to your computer and use it in GitHub Desktop.
Double or one thing google codejam solution
t = int(input())
def getSmallest(word):
n = len(word)
if n == 1:
return word
nchunk = getSmallest(word[1:])
return min(word[0] + nchunk, word[0] * 2 + nchunk)
for tt in range(1, t + 1):
word = input()
print("Case #{}: {}".format(tt, getSmallest(word)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment