v=ReadAscii('Paul:Movies:ValAroRand:ValAroRandValOrder');
nh=ReadAscii('Paul:Users:Peter:MovieOrder:NVHA2');
nb=nh(1:10);
neut1=nh(12:2:210);length(neut1)
nh=nh(11:2:210);length(nh)
%   This software is protected by german copyright and international treaties.             
%   Copyright 2004 Markus Junghöfer & Peter Peyk. All Rights Reserved.                     
%                                                                                          
%   THIS SOFTWARE AND DOCUMENTATION IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE        
%   NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO,    
%   WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE    
%   OF THE SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY THIRD PARTY PATENTS, COPYRIGHTS,
%   TRADEMARKS OR OTHER RIGHTS. COPYRIGHT HOLDERS WILL NOT BE LIABLE FOR ANY DIRECT,       
%   INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF ANY USE OF THE SOFTWARE      
%   OR DOCUMENTATION.                                                                      
ph=ReadAscii('Paul:Users:Peter:MovieOrder:PVHA2');
neut2=ph(12:2:210);length(neut2)
ph=ph(11:2:210);length(ph)
x=zeros(1,400);

i1=0;
i2=0;
i3=0;
i4=0;
for i=1:400
	if v(i)==1
		i1=i1+1;
		x(i)=nh(i1);
	elseif v(i)==2
		i2=i2+1;
		x(i)=ph(i2);
	elseif v(i)==3
		i3=i3+1;
		x(i)=neut1(i3);
	elseif v(i)==4
		i4=i4+1;
		x(i)=neut2(i4);
	end
end
x=[nb',x];
SaveAscii(x)


return
NotOk=1
while NotOk
v=[];
v=zeros(1,400);
v(1,1)=1;
iv=[99 100 100 100];
d=2

for i=2:400
	if v(i-1)==1
		a=[2:4];
		t=[0,iv(2:4)];
		if sum(abs(t(a)-mean(t(a))))>d
			[b,c]=max(t);
		else
			r=randperm(3);
			c=a(r(1));
		end
	elseif v(i-1)==2
		a=[1 3 4];
		t=[iv(1),0,iv(3:4)];
		if sum(abs(t(a)-mean(t(a))))>d
			[b,c]=max(t);
		else
			r=randperm(3);
			c=a(r(1));
		end
	elseif v(i-1)==3
		a=[1 2 4];
		t=[iv(1:2),0,iv(4)];
		if sum(abs(t(a)-mean(t(a))))>d
			[b,c]=max(t);
		else
			r=randperm(3);
			c=a(r(1));
		end
	elseif v(i-1)==4
		a=[1 2 3];
		t=[iv(1:3)];
		if sum(abs(t(a)-mean(t(a))))>d
			[b,c]=max(t);
		else
			r=randperm(3);
			c=a(r(1));
		end
	end
	v(i)=c;
	iv(c)=iv(c)-1;
end
v=v
v1=find(v==1); nv1=length(v1)
v2=find(v==2); nv2=length(v2)
v3=find(v==3); nv3=length(v3)
v4=find(v==4); nv4=length(v4)

w=char
w(v1)='a';
w(v2)='b';
w(v3)='c';
w(v4)='c';
w=w
c6=findstr(w,'cccccc'); nc6=length(c6)
c5=findstr(w,'ccccc'); nc5=length(c5)
c4=findstr(w,'cccc'); nc4=length(c4)
c3=findstr(w,'ccc'); nc3=length(c3)
c2=findstr(w,'cc'); nc2=length(c2)
ab=findstr(w,'ab'); nab=length(ab)
ba=findstr(w,'ba'); nba=length(ba)
ac=findstr(w,'ac'); nac=length(ac)
ca=findstr(w,'ca'); nca=length(ca)
c2a=findstr(w,'cca'); nc2a=length(c2a)
c3a=findstr(w,'ccca'); nc3a=length(c3a)
bc=findstr(w,'bc'); nbc=length(bc)
cb=findstr(w,'cb'); ncb=length(cb)
c2b=findstr(w,'ccb'); nc2b=length(c2b)
c3b=findstr(w,'cccb'); nc3b=length(c3b)

nab_nba=nab-nba
nac_nca=nac-nca
nbc_ncb=nbc-ncb
nc2a_nc2b=nc2a-nc2b
nc3a_nc3b=nc3a-nc3b
nc6=nc6
nc5=nc5
Diff=(abs(nab_nba)+abs(nac_nca)+abs(nbc_ncb)+abs(nc2a_nc2b)+abs(nc3a_nc3b))
pause
if nc6==0 & nc5==0 & Diff<5
	NotOk=0;
end
end

	
	
	
