Created
September 20, 2018 04:10
-
-
Save jterrace/76a817a9bc8cd9a75a1a7a75e0df40b0 to your computer and use it in GitHub Desktop.
Programmatically determine how to distribute your chips for Take Your Chances game
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
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