Created
March 22, 2019 05:53
-
-
Save sehajyang/0ba8b0bdd7aeeeba0141e3b1fbe590da 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
import re | |
def solution(dartResult): | |
st = {'S': 1, 'D': 2, 'T': 3} | |
token = {'#': -1, '*': 2, '': 1} | |
match_list = re.findall(r'(?P<num>\d+)(?P<st>[S,D,T]+)(?P<token>[*,#])?', dartResult) | |
for i, value in enumerate(match_list): | |
if i > 0 and match_list[i][2] is '*': | |
match_list[i - 1] *= 2 | |
match_list[i] = int(match_list[i][0]) ** st[match_list[i][1]] * token[match_list[i][2]] | |
return sum(match_list) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment