Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clear
- %Numero de prisioneros
- Np=100;
- P=1:Np;
- %Numero de intentos
- Ni=50;
- function A2=permutar(A,n1,n2)
- A2=A;
- A2(n1)=A(n2);
- A2(n2)=A(n1);
- endfunction
- function CJ=cajas_desordenadas(N)
- %Generamos etiquetas en cada caja
- CJ=1:N;
- %Desordenaremos las etiquetas haciendo muchas permutaciones
- %1.Cantidad de permutaciones que haremos
- min_permutas=2*N;
- max_permutas=8*N;
- RG=max_permutas-min_permutas+1;
- PR=zeros(RG,1);
- PR=PR+1/RG;
- permutas=discrete_rnd(min_permutas:max_permutas,PR,1);
- %comienza el desorden
- PR=zeros(N,1);
- PR=PR+1/N;
- for i=1:permutas
- cj1=discrete_rnd(1:N,PR,1);
- cj2=discrete_rnd(1:N,PR,1);
- CJ=permutar(CJ,cj1,cj2);
- endfor
- endfunction
- %Ahora se tenemos setup listo. comenzamos con los prisioneros
- function exito=veritasium(N,I)
- exito=true;
- CJ=cajas_desordenadas(N);
- for i=1:N
- j=1; %CONTADOR DE INTENTOS
- k=i; %CAJA A REVISAR
- while j<I+1
- if CJ(k)!=i
- k=CJ(k);
- j=j+1;
- else
- break
- endif
- endwhile
- if j>I
- exito=false;
- break
- endif
- endfor
- endfunction
- for i=1:10000
- A(i)=veritasium(Np,Ni);
- endfor
- Success_percentage_rate=sum(A)/length(A)*100
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement