Author | awtawt |
Submission date | 2019-10-16 10:24:07.162082 |
Rating | 6233 |
Matches played | 212 |
Win rate | 62.74 |
Use rpsrunner.py to play unranked matches on your computer.
def longestRepeatedSubstring(str):
n = len(str)
LCSRe = [[0 for x in range(n + 1)]
for y in range(n + 1)]
res = "" # To store result
res_length = 0 # To store length of result
# building table in bottom-up manner
index = 0
for i in range(1, n + 1):
for j in range(i + 1, n + 1):
# (j-i) > LCSRe[i-1][j-1] to remove
# overlapping
if (str[i - 1] == str[j - 1] and
LCSRe[i - 1][j - 1] < (j - i)):
LCSRe[i][j] = LCSRe[i - 1][j - 1] + 1
# updating maximum length of the
# substring and updating the finishing
# index of the suffix
if (LCSRe[i][j] > res_length):
res_length = LCSRe[i][j]
index = max(i, index)
else:
LCSRe[i][j] = 0
# If we have non-empty result, then insert
# all characters from first character to
# last character of string
if (res_length > 0):
for i in range(index - res_length + 1,
index + 1):
res = res + str[i - 1]
return res
import random
previous = input
if previous == "":
pattern = "RPS"
def beat(choise):
if choise == "R":
return "P"
elif choise == "P":
return "S"
else:
return "R"
if previous != "":
pattern += previous
last_1000 = pattern[-50:]
sub = longestRepeatedSubstring(last_1000)
if sub == "":
output = beat(random.choice(last_1000))
else:
index = pattern.find(sub) + len(sub)
if index >= len(sub):
output = beat(random.choice(last_1000))
else:
output = beat(last_1000[index])