Skip to content

Instantly share code, notes, and snippets.

@synsh
Created March 4, 2018 11:55
Show Gist options
  • Save synsh/6e582190e576eccc622ecb8fd0d81a7a to your computer and use it in GitHub Desktop.
Save synsh/6e582190e576eccc622ecb8fd0d81a7a to your computer and use it in GitHub Desktop.
def orangecap(d):
(name, max_score, max_name) = ({}, 0, '')
for match in d:
for player in d[match]:
if player not in name:
name[player] = 0
name[player] += d[match][player]
for player in name:
if name[player] > max_score:
(max_score, max_name) = (name[player], str(player))
output = max_name,max_score
return(output)
def addpoly(p, q):
result = []
for i in q:
add = True
for j in p:
if i[1] == j[1]:
add = False
break
if(add):
result.append(i)
for i in p:
add = True
for j in q:
if i[1] == j[1]:
s = i[0] + j[0]
if s != 0:
result.append((s,i[1]))
add = False
if(add):
result.append(i)
return(result)
def multpoly(p,q):
(mul, result, copy) = ([], [], [])
for i in p:
for j in q:
(m, s) = (i[0] * j[0], i[1] + j[1])
mul.append((m,s))
for i in range(0, len(mul)):
add = True
for j in range(i+1, len(mul)):
if mul[i][1] == mul[j][1]:
add = False
(c, e) = (mul[i][0] + mul[j][0], mul[j][1])
if c!=0:
result.append((c,e))
copy.append(mul[j])
if(add and (mul[i] not in copy)):
result.append(mul[i])
return(result)
# Hidden code below
import ast
def todict(inp):
inp = ast.literal_eval(inp)
return (inp)
def topairoflists(inp):
inp = "["+inp+"]"
inp = ast.literal_eval(inp)
return (inp[0],inp[1])
def tostring(s):
lquote = s.find('"')
rquote = s.rfind('"')
return(s[lquote+1:rquote])
def tolist(s):
lbrack = s.find('[')
rbrack = s.rfind(']')
slist = s[lbrack+1:rbrack].split(',')
if slist == ['']:
slist = []
else:
for i in range(0,len(slist)):
slist[i] = int(slist[i])
return(slist)
fncall = input()
lparen = fncall.find("(")
rparen = fncall.rfind(")")
fname = fncall[:lparen]
farg = fncall[lparen+1:rparen]
if fname == "orangecap":
arg = todict(farg)
print(orangecap(arg),end="")
elif fname == "addpoly":
(arg1,arg2) = topairoflists(farg)
print(addpoly(arg1,arg2),end="")
elif fname == "multpoly":
(arg1,arg2) = topairoflists(farg)
print(multpoly(arg1,arg2),end="")
else:
print("Function", fname, "unknown")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment