Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Numbered Triangles by TovarischZhukov
def find(data,el):
retval=[]
if 1/len(data):
data=data[0]
intrs=inters(data,el)
left=[val[0] for val in intrs if val[1]]
right=[val[0] for val in intrs if not val[1]]
for lval in left:
for rval in right:
try:
vd=data[:]; vd.remove(lval); vd.remove(rval); vel=el[:]
vel[0]=vel[0][:]; vel[0].remove(lval)
vel[-1]=vel[-1][:]; vel[-1].remove(rval)
retval.append(sum(val[0] for val in [vd]+vel))
except:pass
else:
for val in data:
intr=inters(val,el)
for vint in intr:
new_data=data[:];new_data.remove(val)
fval=val[:]; fval.remove(vint[0])
fel=el[:]
k=0 if vint[1] else -1
fel[k]=fel[k][:]
fel[k].remove(vint[0])
fel.insert(k,fval)
ret=find(new_data,fel)
if ret:retval+=[ret]
return max(retval) if retval else 0
def inters(val,el):
sval=set(val)
r=[(intr,True) for intr in sval.intersection(set(el[0]))]
if len(el)>1: r+=[(intr,False) for intr in sval.intersection(set(el[-1]))]
return r
def checkio(data):
retval=[]
for val in data:
new_data=data[:]
new_data.remove(val)
retval+=[find(new_data,[val])]
return max(retval)if retval else 0
Feb. 2, 2016