Codejam Qualification Round 2018. Task 3
Python Only
def go_gopher(a):
k=a//3+1
l=k//3
ra=[3*i+2 for i in list(range(l))]
if k-1>ra[-1]:
ra+=[k-1]
c=1000
go_ra=[ra[j%len(ra)] for j in range(c)]
for i in go_ra:
x,y=[i-1,i,i+1],[1,2,3]
xy=[' '.join([str(el) for el in [xy1,xy2]])
for xy1 in x for xy2 in y]
flag=False
while xy!=[]:
out_xy='%d 2'%i
print(out_xy,flush=True)
in_xy=input()
if in_xy in xy:
xy.remove(in_xy)
elif in_xy=='0 0':
flag=True
break
elif in_xy=='-1 -1':
exit()
# print(xy)
if flag==True:
break
T=int(input())
for i in range(T):
A=int(input())
go_gopher(A)
xxxxxxxxxx
def random_coords(i):
y=randint(1,3)
x=randint(i-1,i+1)
return (x,y)
def go_gopher(
T=selector([1,2,3],default=1,label='$\\mathbb{T}$'),
A=input_box('20|50|80',type=str,label='$\\mathbb{A}$',width=25)):
A=int(str(A).split('|')[T-1])
pretty_print(html('$\\mathbb{T=%d; \\; A=%d}$'%(T,A)))
pretty_print(html('output & input messages \n'))
k=A//3+1; l=k//3; count=0
ra=[3*i+2 for i in list(range(l))]
if k-1>ra[-1]:
ra+=[k-1]
for i in ra:
x,y=[i-1,i,i+1],[1,2,3]
xy=[' '.join([str(el) for el in [xy1,xy2]])
for xy1 in x for xy2 in y]
flag=False
while xy!=[]:
count+=1
out_xy='%d 2'%i
in_xy='%d %d'%random_coords(i)
st='#0%d; output: '%count+out_xy+'; input: '+in_xy
pretty_print(html(st))
if in_xy in xy:
xy.remove(in_xy)
elif in_xy=='0 0':
flag=True
break
elif in_xy=='-1 -1':
exit()
if flag==True:
break
pretty_print(html('the number of interactions - %d'%count))