Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/local/bin/pypy
'''
RESULTS
========
63 / 64 : 603228 points (10, 0, 0)
61 / 64 : 479408 points [9, 0, 1]
5 / 64 : 477912 points [0, 6, 4]
4 / 64 : 477270 points [0, 5, 5]
62 / 64 : 473971 points [9, 1, 0]
6 / 64 : 471463 points [0, 7, 3]
3 / 64 : 465273 points [0, 4, 6]
7 / 64 : 460515 points [0, 8, 2]
8 / 64 : 449784 points [0, 9, 1]
2 / 64 : 435944 points [0, 3, 7]
'''
from random import randrange
def sumOfDigits(number):
if number < 0:
return None
out = 0
while number > 0:
out += number % 10
number = number // 10
return out
def numberOfDigits(number):
if number < 0:
number = number * (-1)
out = 0
while number > 0:
out += 1
number = number // 10
return out
def digitsAsList(number, minSize):
out = []
numberCopy = number
while number > 0:
out.append(number % 10)
number = number // 10
while minSize > numberOfDigits(numberCopy):
out.append(0)
minSize = minSize - 1
return out[::-1] # reverses a list
def rps_amount(pick1, pick2):
if pick1 == 'r' and pick2 == 's':
return 3
if pick1 == 'p' and pick2 == 'r':
return 2
if pick1 == 's' and pick2 == 'p':
return 1
return 0
def pickRPS(prob1, prob2):
if rand1 <= prob1:
return 'r'
elif rand1 <= prob1 + prob2:
return 'p'
return 's'
numberOfRounds = 10000
if __name__ == '__main__':
players = []
for crt in range(911):
if sumOfDigits(crt) == 10:
players.append(digitsAsList(crt, 3))
players.append([10, 0, 0])
players.append([0, 10, 0])
players.append([0, 0, 10])
n = len(players)
points = [0] * n
for i in range(n):
for j in range(i, n):
# play a number of rounds between i and j
for round in range(numberOfRounds):
rand1 = randrange(99)
rand2 = randrange(99)
pick1 = pickRPS(players[i][0] * 10, players[i][1] * 10)
pick2 = pickRPS(players[j][0] * 10, players[j][1] * 10)
points[i] += rps_amount(pick1, pick2)
points[j] += rps_amount(pick2, pick1)
best = [0] * 10
for i in range(len(players)):
if points[i] > points[best[0]]:
best[0] = i
for j in range(len(best) - 1):
if points[best[j]] > points[best[j+1]]:
best[j], best[j+1] = best[j+1], best[j]
else:
break
for crt in best[::-1]:
print crt, '/', n, ': ', points[crt], ' points', players[crt]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment