clear A=zeros(10); B=randperm(100); B=B(1:64); A(B)=1; A=[0 1 0 1 1 0 1 0 1 1; 1 1 1 1 1 0 1 1 1 0; 1 1 1 1 0 1 1 1 1 1; ... 1 0 1 1 1 0 0 1 0 1; 1 1 1 0 1 0 0 0 0 1; 1 0 0 1 0 0 0 1 1 1; ... 1 0 0 1 1 1 0 1 1 1; 0 1 1 1 0 1 1 1 1 0; 0 0 1 0 0 1 1 1 1 0; ... 1 1 0 0 1 1 0 1 1 0]; A=[A zeros(10,1)]; row_streaks=zeros(10,5); for i=1:10 j=1; k=1; while j < 10+1 if A(i,j)==1 row_streaks(i,k)=row_streaks(i,k)+1; while (A(i,j)-A(i,j+1)) ~= 1 row_streaks(i,k)=row_streaks(i,k)+1; j=j+1; end k=k+1; end j=j+1; end end A=A(:,1:10); A=A'; A=[A zeros(10,1)]; col_streaks=zeros(10,5); for i=1:10 j=1; k=1; while j < 10+1 if A(i,j)==1 col_streaks(i,k)=col_streaks(i,k)+1; while (A(i,j)-A(i,j+1)) ~= 1 col_streaks(i,k)=col_streaks(i,k)+1; j=j+1; end k=k+1; end j=j+1; end end col_streaks=col_streaks'; A=A(:,1:10); A=A'; A, row_streaks, col_streaks nono_res=0.5*ones(10); for i=1:10 sor_vektor=row_streaks(i,:); vip_num=sum(sor_vektor)+numel(find(sor_vektor))-1; for q=1:numel(find(sor_vektor)) r=sor_vektor(q); if (vip_num+r)>10 to_enter=vip_num+r-10; a=sum(sor_vektor(1:q))+(q-1); nono_res(i,a:-1:a-to_enter+1)=1; end end if vip_num==10 x=find(nono_res(i,:)==0.5); nono_res(i,x)=0; end end for j=1:10 oszlop_vektor=col_streaks(:,j); vip_num=sum(oszlop_vektor)+numel(find(oszlop_vektor))-1; for q=1:numel(find(oszlop_vektor)) r=oszlop_vektor(q); if (vip_num+r)>10 to_enter=vip_num+r-10; a=sum(oszlop_vektor(1:q))+(q-1); nono_res(a:-1:a-to_enter+1,j)=1; end end if vip_num==10 x=find(nono_res(:,j)==0.5); nono_res(x,j)=0; end end % ones_to_be_entered=sum(sum(nono_res))-sum(sum(A)) imview(1-nono_res,'InitialMagnification','fit') % imshow(1-nono_res)