Python, 79117910 (7704 + 207206)
This was inspired by shell sort. I found relatively good coefficients for the gap sequence (g
) by checking a few hundred alternatives. The number of comparisons is limited by counting explicitly (n
).
s=1
while s:
s=map(int,raw_input().split());k=len(s);n=2*k;g=13*k/23
while g:
for i in range(g,k):
n-=1
if n<0:break
if s[i]<s[i-g]:s[i],s[i-g]=s[i-g],s[i]
g=6*gg=3*g/105
print' '.join(map(str,s))