Created
April 22, 2016 19:07
-
-
Save dstarcev/1db160606885e0977529cba7cb2ee2e1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sum_str(left, right): | |
if left == '': return right | |
elif right == '': return left | |
char_sum_str = sum_char(left[-1], right[-1]) | |
rest_sum_str = sum_str(left[:-1], right[:-1]).strip('0') | |
if len(char_sum_str) == 1: | |
return rest_sum_str + char_sum_str | |
return sum_str(rest_sum_str, char_sum_str[0]) + char_sum_str[1] | |
def sum_char(left, right): | |
return { | |
'00': '0', | |
'01': '1', | |
'02': '2', | |
'03': '3', | |
'04': '4', | |
'05': '5', | |
'06': '6', | |
'07': '7', | |
'08': '8', | |
'09': '9', | |
'10': '1', | |
'11': '2', | |
'12': '3', | |
'13': '4', | |
'14': '5', | |
'15': '6', | |
'16': '7', | |
'17': '8', | |
'18': '9', | |
'19': '10', | |
'20': '2', | |
'21': '3', | |
'22': '4', | |
'23': '5', | |
'24': '6', | |
'25': '7', | |
'26': '8', | |
'27': '9', | |
'28': '10', | |
'29': '11', | |
'30': '3', | |
'31': '4', | |
'32': '5', | |
'33': '6', | |
'34': '7', | |
'35': '8', | |
'36': '9', | |
'37': '10', | |
'38': '11', | |
'39': '12', | |
'40': '4', | |
'41': '5', | |
'42': '6', | |
'43': '7', | |
'44': '8', | |
'45': '9', | |
'46': '10', | |
'47': '11', | |
'48': '12', | |
'49': '13', | |
'50': '5', | |
'51': '6', | |
'52': '7', | |
'53': '8', | |
'54': '9', | |
'55': '10', | |
'56': '11', | |
'57': '12', | |
'58': '13', | |
'59': '14', | |
'60': '6', | |
'61': '7', | |
'62': '8', | |
'63': '9', | |
'64': '10', | |
'65': '11', | |
'66': '12', | |
'67': '13', | |
'68': '14', | |
'69': '15', | |
'70': '7', | |
'71': '8', | |
'72': '9', | |
'73': '10', | |
'74': '11', | |
'75': '12', | |
'76': '13', | |
'77': '14', | |
'78': '15', | |
'79': '16', | |
'80': '8', | |
'81': '9', | |
'82': '10', | |
'83': '11', | |
'84': '12', | |
'85': '13', | |
'86': '14', | |
'87': '15', | |
'88': '16', | |
'89': '17', | |
'90': '9', | |
'91': '10', | |
'92': '11', | |
'93': '12', | |
'94': '13', | |
'95': '14', | |
'96': '15', | |
'97': '16', | |
'98': '17', | |
'99': '18', | |
}[left + right] | |
print(sum_str('1', '3')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment