Skip to content

Instantly share code, notes, and snippets.

@sehajyang
Created March 22, 2019 05:53
Show Gist options
  • Save sehajyang/0ba8b0bdd7aeeeba0141e3b1fbe590da to your computer and use it in GitHub Desktop.
Save sehajyang/0ba8b0bdd7aeeeba0141e3b1fbe590da to your computer and use it in GitHub Desktop.
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