본문 바로가기
Programming/Matlab, Octave, Scilab

[Matlab/Octave] Programing for 8145060 of lotto combinations

by 도파공 2010. 5. 1.
728x90
반응형
% ============================================================================

% Octave 또는 Matlab에서 사용하면 된다. 다른 언어의 경우 수정이 필요하다.

% 저장방법은 별도 포함시키지 않았다. 그리고 시간이 많이 소요되기 때문에

% 프로그래밍에 관심이 있으신 분만 활용 바란다.

% ============================================================================
% octave : if - endif, while - endwhile, for-endfor ...



N=8145060; % 조합 총수

lotto=zeros(N,7); % 메모리 할당

tmp1=0;
tmp2=0;
tmp3=0;
tmp4=0;
tmp5=0;
tmp6=0;

for count=1:N
   
    lotto(count,1)=count;
    lotto(count,2)=1+tmp1;
    lotto(count,3)=2+tmp1+tmp2;
    lotto(count,4)=3+tmp1+tmp2+tmp3;
    lotto(count,5)=4+tmp1+tmp2+tmp3+tmp4;
    lotto(count,6)=5+tmp1+tmp2+tmp3+tmp4+tmp5;
    lotto(count,7)=6+tmp1+tmp2+tmp3+tmp4+tmp5+tmp6;

    tmp6=tmp6+1;
   
    if lotto(count,7)==45
        tmp6=0;
        tmp5=tmp5+1;

        if lotto(count,6)==44
            tmp5=0;
            tmp4=tmp4+1;
           
            if lotto(count,5)==43
                tmp4=0;
                tmp3=tmp3+1;
               
                if lotto(count,4)==42
                    tmp3=0;
                    tmp2=tmp2+1;

                    if lotto(count,3)==41
                        tmp2=0;
                        tmp1=tmp1+1;
                    end
                end
            end
        end
    end
end



% ============================================================================
728x90
반응형

댓글