Skip to content

Instantly share code, notes, and snippets.

@junho85
Created September 13, 2018 15:05
Show Gist options
  • Save junho85/624360a36dcf8d1a8632a1389a5b9e59 to your computer and use it in GitHub Desktop.
Save junho85/624360a36dcf8d1a8632a1389a5b9e59 to your computer and use it in GitHub Desktop.
PS2 - 다트게임 - 2018 KAKAO BLIND RECRUITMENT
import re
def multiple(str):
if str == 'S':
return 1
elif str == 'D':
return 2
else: # T
return 3
def s(a, b):
return pow(int(a), multiple(b))
def is_star(str):
if len(str) == 1:
return False
elif str[1] == '*':
return True
else:
return False
def is_acha(str):
if len(str) == 1:
return False
elif str[1] == '#':
return True
else:
return False
def solution(dartResult):
r = re.compile("([0-9]+)([A-Z*#]+)([0-9]+)([A-Z*#]+)([0-9]+)([A-Z*#]+)")
m = r.match(dartResult)
score1 = s(m.group(1), m.group(2)[0])
if is_acha(m.group(2)):
score1 *= -1
elif is_star(m.group(2)):
score1 *= 2
score2 = s(m.group(3), m.group(4)[0])
if is_acha(m.group(4)):
score2 *= -1
elif is_star(m.group(4)):
score1 *= 2
score2 *= 2
score3 = s(m.group(5), m.group(6)[0])
if is_acha(m.group(6)):
score3 *= -1
elif is_star(m.group(6)):
score2 *= 2
score3 *= 2
answer = score1 + score2 + score3
return answer
# test
assert(solution('1S2D*3T') == 37)
assert(solution('1D2S#10S') == 9)
assert(solution('1D2S3T*') == 59)
@junho85
Copy link
Author

junho85 commented Sep 16, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment