Skip to content

Instantly share code, notes, and snippets.

@jterrace
Created September 20, 2018 04:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jterrace/76a817a9bc8cd9a75a1a7a75e0df40b0 to your computer and use it in GitHub Desktop.
Save jterrace/76a817a9bc8cd9a75a1a7a75e0df40b0 to your computer and use it in GitHub Desktop.
Programmatically determine how to distribute your chips for Take Your Chances game
import sys
DICE_SIDES = 6
distribution = [0] * DICE_SIDES
for d1 in range(1, DICE_SIDES + 1):
for d2 in range(1, DICE_SIDES + 1):
delta = abs(d1 - d2)
distribution[delta] += 1
distribution = [
ct / float(DICE_SIDES * DICE_SIDES)
for ct in distribution]
chips = int(sys.argv[1])
assignments = [0] * DICE_SIDES
for chip in range(chips):
largest_drift_index = 0
largest_drift = -1
for index, chips_assigned in enumerate(assignments):
drift = distribution[index]
if chip > 0:
drift = drift - float(chips_assigned) / chip
if drift > largest_drift:
largest_drift = drift
largest_drift_index = index
assignments[largest_drift_index] += 1
print assignments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment