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