Created
May 28, 2014 17:13
-
-
Save RobertCorey/5fcdc0e6b07ba56fb91a to your computer and use it in GitHub Desktop.
Secretary Solution Daut Modulated Liquid Poker bad math
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 math | |
import random | |
def dautFind(sec): | |
random.shuffle(sec) | |
START_LENGTH = len(sec) | |
currentLength = START_LENGTH | |
end = int(currentLength / math.e) | |
maxRank = max(sec[0:end]) | |
# print "In the first n/e elements the greatest value found was ", maxRank | |
currentRank = 0 | |
start = end | |
currentLength = START_LENGTH - start | |
end = start + int( currentLength / math.e) | |
found = False | |
while start != len(sec) - 1 and not found: | |
# print "The current max rank is ", maxRank | |
# print "Start Index: ", start | |
# print "End Index: ", end | |
# print "Current Set", sec[start:end] | |
currentRank = max(sec[start:end]) | |
if currentRank > maxRank: | |
# print "The maximum value of the current set ", currentRank, " is greater than the current max of ", maxRank | |
found = True | |
else: | |
maxRank = currentRank | |
# print "The new max is: ", maxRank | |
start = end | |
currentLength = START_LENGTH - start | |
end = start + int( currentLength / math.e) | |
#special where rounding causes the index at n-2 not to be evaluated | |
if start == end and end != START_LENGTH: | |
end += 1 | |
if found: | |
return currentRank | |
else: | |
return sec[START_LENGTH - 1] | |
NUMBER_OF_SEC = 50 | |
NUMBER_OF_TRIALS = 100000 | |
sec = list(range(0, NUMBER_OF_SEC)) | |
winners = 0 | |
total = 0 | |
for x in range(NUMBER_OF_TRIALS): | |
result = dautFind(sec) | |
total += result | |
if result == (NUMBER_OF_SEC - 1): | |
winners += 1 | |
print float(total) / float(NUMBER_OF_TRIALS) | |
print float(winners) / float(NUMBER_OF_TRIALS) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment