Skip to content

Instantly share code, notes, and snippets.

@sshh12
Last active November 17, 2017 00:35
Show Gist options
  • Save sshh12/ee5dbb3c853313ee9c2ec1c80e820841 to your computer and use it in GitHub Desktop.
Save sshh12/ee5dbb3c853313ee9c2ec1c80e820841 to your computer and use it in GitHub Desktop.
PickANumber
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