program Statistics_Module_4; //************************************************** //all 4 examples discuss a combination lock (Zahlenschloss) //loc's = 198, ex. 212_ , adapt from _92 //...we discuss the 4 types of stat with a combination lock (zahlenschloss): {1. Permutation = n! 2. Permutation(Variation without repeating) = nPr = n!/(n-k)! 3. Combination (binominal coefficient)= nCr = nPr / k! 4. Variation(repeating) = n^k where, n,k are non negative integers and k<=n. k is the size of each permutation. n is the size of a set from which elements are permuted. ! is the factorial operator. 1 Anordnungen (Permutationen) 2 Auswählen mit Beachtung der Reihenfolge (Variationen) * 2.1 Variation ohne Zurücklegen * 4.1 Variation mit Zurücklegen 3 Auswählen ohne Beachtung der Reihenfolge (Kombinationen) ------------------------------------------------------------------------------ {1. ex. lock of 4 numbers [0..3] permuatation, ex. [0123], 4! = 24 results 2. ex. 4 lock with 10 numbers [0..9] permutation, ex. [3579], nPr(10,4) = 5040 results 3. ex. 21 lock with 4 possibilities, ex. [000010000100010100000] nCr(20,4) = 4845 results 4. ex. 4 lock with 10 numbers (norm case), ex. [1122], 10^4 = 10000 results -----------------------------------------------------------------------------} const DIM = 660; PI2 = 6.28318530717958647692528676655901; E = 2.718281828459; SEP = '----------------------------------------------------'; BODY = 23; EMOTION = 28; SPIRIT = 33; type TBIOVector = array[0..DIM] of TPoint; Tperm = array[1..4] of byte; TCube = array[1..6] of byte; var hnd: THandle; mname, mdes: string; mfilel: TStringList; st_string: shortstring; time1, time2, diff: TDateTime; // 1. Permutation n! //-------------------------------------------------------------- Procedure One_Permutation_4; var i,k,l,m: byte; count: integer; begin count:= 0; for i:= 0 to 3 do for k:= 0 to 3 do for l:= 0 to 3 do for m:= 0 to 3 do begin if (i<>k) and (i<>l) and (i<>m) and (k<>l) and (k<>m) and (l<>m) then begin inc(count); Writeln(Format('Case: %d - %d%d%d%d',[count,i,k,l,m])) //inc(i); inc(k); end; end; Writeln(IntToStr(count)+' Permutations') Writeln('All Permutations of 0..3: '+intToStr(round(Fact(4)))) Writeln(SEP) end; // 2. Permutation(Variation without repeating) = nPr = n!/(n-k)! //-------------------------------------------------------------- Procedure Two_Permutation_4_of_10; var i,k,l,m: byte; count: integer; begin count:= 0; for i:= 0 to 9 do for k:= 0 to 9 do for l:= 0 to 9 do for m:= 0 to 9 do begin if (i<>k) and (i<>l) and (i<>m) and (k<>l) and (k<>m) and (l<>m) then begin inc(count); Writeln(Format('Case: %d - %d%d%d%d',[count,i,k,l,m])) //inc(i); inc(k); end; end; Writeln(intToStr(count)+' Permutations') Writeln('All Permutations 4 of 10: '+intToStr(round(Fact(10)/Fact(10-4)))) Writeln(SEP) end; // 3. Combination (binominal coefficient)= nCr = nPr / k! //------------------------------------------------------- procedure Three_Combination_without_Order_4_of_20; //binominal coefficient)= nCr = nPr / k! //4 of 20 = 4845 = NCR(20,4) on a calculator or a lotto 4 of 20 var i,k,l,m,n,o,p,q,r,s,t,u,v,w,q1,r1,s1,t1,u1,v1: byte; count: integer; begin i:=1; k:=1; l:=1; m:=1; n:=1; o:= 1; p:=1; q:=1; r:=1; s:=1; t:=1; u:=1; v:= 1; w:=1; q1:=1; r1:=1; s1:=1; t1:=1; u1:=1; v1:= 1; count:= 0; for i:= 0 to 1 do for k:= 0 to 1 do for l:= 0 to 1 do for m:= 0 to 1 do for n:= 0 to 1 do for o:= 0 to 1 do for p:= 0 to 1 do for q:= 0 to 1 do for r:= 0 to 1 do for s:= 0 to 1 do for t:= 0 to 1 do for u:= 0 to 1 do for v:= 0 to 1 do for w:= 0 to 1 do for q1:= 0 to 1 do for r1:= 0 to 1 do for s1:= 0 to 1 do for t1:= 0 to 1 do for u1:= 0 to 1 do for v1:= 0 to 1 do if i+k+l+m+n+o+p+q+r+s+t+u+v+w+q1+r1+s1+t1+u1+v1 = 4 then begin inc(count); Writeln(Format('Case: %d - %d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d', [count,i,k,l,m,n,o,p,q,r,s,t,u,v,w,q1,r1,s1,t1,u1,v1])); end; Writeln(inttostr(count)+' All combinations in a Set') Writeln(SEP) end; // 4. Variation (repeating) = n^k //------------------------------------ procedure Four_Variation_Lock_4; //solution is n^k = 10^4 = 10000 var i,k,l,m: byte; count: integer; begin i:=1; k:=1; l:=1; m:=1; count:= 0; for i:= 0 to 9 do for k:= 0 to 9 do for l:= 0 to 9 do for m:= 0 to 9 do begin inc(count); writeln(Format('Case: %d - %d%d%d%d',[count, i,k,l,m])) end; Writeln(inttostr(count)+' All Variations of a Lock') Writeln(SEP) end; // main calc & plot begin //Sudoku_permutation_1; maxForm1.ShellStyle1Click(self); st_String:= 'STATISTIC MODULE 4'; Writeln(st_String) time1:= time; //Showmessage(' First a 4 of 4 permutation') One_Permutation_4; //Showmessage(' Second a 4 of 10 permutation') Two_Permutation_4_of_10; //Showmessage(' Third a 20 of 4 combination') Three_Combination_without_Order_4_of_20; //Showmessage(' Fourth a 4 of 10 variation') Four_Variation_Lock_4; time2:= time; Diff:= time2 - time1; writeln(FormatDateTime('" Statistic Module run time is:" nn:ss:zzz',Diff)); Writeln(st_String) //maxForm1.SaveOutput1Click(self); writeln('maXbox V: '+GetVersionString('maxbox3.exe')) //hnd:= ExecuteFile('maxbox3.exe','',ExePath,1) //writeln(inttostr(hnd)) getAssociatedProgram('.pdf',mname, mdes) writeln(mname + mdes) mfilel:= TStringlist.create; //FilesFromWildcard(Exepath, '21*.txt',mfilel, true, true, true) //Writeln(mfilel.text) mfilel.Free; end. just maXbox ____ ___ _ ____ _ _ _ | _ \ | _| | | | _ \ | | | | | | | | . | | |_ | | | |_| | | |_| | | | | | | | | _| | | | __/ | _ | | | | |_. | | |_ | |__ | | | | | | | | |____/ |___| |____| |_| |_| |_| |_|