Last active
November 17, 2017 00:35
-
-
Save sshh12/ee5dbb3c853313ee9c2ec1c80e820841 to your computer and use it in GitHub Desktop.
PickANumber
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 get_scores(nums, turn=0, a=0, b=0): | |
if len(nums) == 0: | |
return (a, b) | |
else: | |
left = get_scores(nums[1:], | |
turn ^ 1, | |
a + nums[0] * (1 - turn), | |
b + nums[0] * turn) | |
right = get_scores(nums[:-1], | |
turn ^ 1, | |
a + nums[-1] * (1 - turn), | |
b + nums[-1] * turn) | |
if left[turn] > right[turn]: | |
return left | |
else: | |
return right | |
print(get_scores([1, 1, 8, 7])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment