Winner the cyclist (typ2)

2006-04-12 09:00:00 UTC

# What A Mess -14

by DrSuess

Status: Passed
Results: 84386
CPU Time: 64.219
Score: 846.924
Submitted at: 2006-04-12 16:59:35 UTC
Scored at: 2006-04-13 01:24:48 UTC

Current Rank: 48th
Based on: What A Mess -13 (diff)
Basis for: What A Mess -15 (diff)

Code
```function X9=solver(C3,Z1)
[V9,J1]=size(C3);
X9=ones(Z1,3);
P4=0;
M3=rand(4,1);
if(V9*J1)>10.5*Z1
Q2=40;
A7=.847;
E1=2.93;
P2=1.566;
elseif(V9*J1)>8.5*Z1
Q2=29;
A7=.847;
E1=2.93;
P2=1.566;
elseif V9*J1>=256
Q2=26;
A7=.951;
E1=2.8;
P2=1.4;
else
Q2=26;
A7=0.945;
E1=2.97;
P2=1.46;
end
C3=nthroot(C3,P2);
P1=ceil(E1*Z1/10);
Y1=floor((0.66+(rand-0.5)*0.1)*Z1);
while 1
if P4==Y1,C3=nthroot(C3,2/(1+P2));end
[U6,S0,O4]=J0(V9,J1,C3);
if isempty(U6),
[W0,C3]=C4(V9,J1,C3);
if W0(1)
P4=P4+1;
X9(P4,:)=W0;
if(P4==Z1)
break;
end
continue
end
break
end
if P4<Z1-1
[S0,T8]=sort(S0,2,'descend');
U6=U6(T8);
for T7=1:min(numel(U6),Q2)
B4=E9(C3,O4,U6(T7),V9);
[Q3,T5]=J0(V9,J1,B4);
if(~isempty(Q3))
W9=max(min(P1,Z1-P4-3),1);
if numel(T5)<=W9
S0(T7)=S0(T7)+sum(T5);
else
T5=sort(T5,2,'descend');
S0(T7)=S0(T7)+sum(T5(1:W9));
end
end
if(S0(T7)<A7*S0(1))
break;
end
end
end
[J3,T8]=max(S0);
D8=U6(T8);
P4=P4+1;
X9(P4,:)=[mod(D8-1,V9)+1,ceil(D8/V9),0];
C3=E9(C3,O4,D8,V9);
if(P4==Z1)
break;
end
end
X9=X9(1:P4,:);
function[U6,S0,O4]=J0(V9,J1,C3)
O4=zeros(V9,J1);
T0=1;% find(any(C3,2),1);
if(T0==1)
N7=C3(1);
if N7
O4(1)=1;
end
T7=1;
for j=2:J1
I6=T7;
T7=T7+V9;
C8=N7;
N7=C3(T7);
if N7
O4(T7)=T7;
if(C8==N7)
O4(I6)=T7;
end
end
end
end
for i=max(2,T0):V9
T7=i;
N7=C3(T7);
if(N7)
O4(T7)=T7;
I6=T7-1;
if(C3(I6)==N7)
n=-1;
while(n ~=I6)
n=I6;
I6=O4(n);
O4(n)=T7;
end
end
end
for j=2:J1
T7=T7+V9;% move H1 P3 I7
C8=N7;
N7=C3(T7);
if(N7)
O4(T7)=T7;
if(C8==N7)
O4(T7-V9)=T7;
end
if(C3(T7-1)==N7)
n=-1;
I6=T7 - 1;
while(n ~=I6)
n=I6;
I6=O4(n);
O4(n)=T7;
end
end
end
end
end
U6=zeros(1,256);
U2=0;
N2=zeros(V9,J1);
for i=V9:-1:T0
T7=i+V9*(J1-1);
for j=1:J1
if C3(T7)
I6=O4(T7);
if(I6==T7)
N2(T7)=1;
else
while N2(I6)==0
I6=O4(I6);
end
O4(T7)=O4(I6);
K3=N2(I6)+1;
N2(I6)=K3;
if(K3==2)
U2=U2+1;
U6(1,U2)=I6;
end
O4(I6)=T7;
end
end
T7=T7 - V9;
end
end
U6=U6(1:U2);
S0=zeros(1,U2);
for T7=1:U2
I6=U6(T7);
U6(T7)=O4(I6);
S0(T7)=N2(I6)*C3(I6);
O4(I6)=I6;
end
function U1=E9(U1,G8,cell,G6)
W6=cell;
U1(W6)=0;
C1=ceil(W6/G6);
R3=C1;U3=C1;
while G8(W6)~=W6
W6=G8(W6);
U1(W6)=0;
C1=ceil(W6/G6);
R3=min(R3,C1);
U3=max(U3,C1);
end;
for i=R3:U3,
T7=U1(U1(:,i)>0,i);
U1(:,i)=0;U1(G6-numel(T7)+1:G6,i)=T7;
end
function[W0,Q6]=C4(V9,J1,C3)
Z7=[-1 V9 1 -V9];
H4=V9*J1;
W0=zeros(1,3);
Q6=C3;
O8=0;
Z0=find(C3~=0)';
F6=numel(Z0);
for T7=1:F6
E3=Z0(T7);
for L1=1:4
P5=E3+Z7(L1);
if P5>0 && P5<=H4 && C3(P5)>0 && C3(P5)~=C3(E3)
U4=C3;U4([E3,P5])=U4([P5,E3]);
[Y6,B5]=J0(V9,J1,U4);
if(~isempty(B5))
if(max(B5)>O8)
O8=max(B5);
B8=E3;N5=L1;X7=P5;
end
else
for M0=max(1,T7-10):min(F6,T7+10)
D5=Z0(M0);
for Z2=1:4
X0=D5+Z7(Z2);
if X0>0 && X0<=H4 && U4(X0)>0 && U4(X0)~=U4(D5)
K1=U4;K1([D5,X0])=K1([X0,D5]);
[E7,W2,K4]=J0(V9,J1,K1);
if(~isempty(W2)&& max(W2)>O8)
[M8,U0]=max(W2);
N8=E7(U0);
while(K4(N8)~=N8)
N8=K4(N8);
end
if(N8==P5 || N8==E3)
O8=max(W2);
B8=E3;N5=L1;X7=P5;
end
end
end
end
end
end
end
end
end
if(O8>0)
W0=[mod(B8-1,V9)+1,ceil(B8/V9),N5];
Q6=C3;Q6([B8,X7])=U4([X7,B8]);
end
function C3=R2(C3,A9,H7)
C3([A9,H7])=C3([H7,A9]);```