I'm doing an algorithm that gives the combination in 4 digits from A to Z. I did using vectors in Pascal like this:
var
i:integer;
j:integer;
k:integer;
l:integer;
vect1:array[1..26] of string;
vect2:array[1..26] of string;
vect3:array[1..26] of string;
vect4:array[1..26] of string;
aux:array[1..26] of string;
Wordlist:text;
begin
aux[1]:= 'a';
aux[2]:= 'b';
aux[3]:= 'c';
...
aux[24]:= 'x';
aux[25]:= 'y';
aux[26]:= 'z';
Assign(Wordlist, 'Wordlist.txt');
Rewrite(Wordlist);
for i:= 1 to 26 do
for j:= 1 to 26 do
for k:= 1 to 26 do
for l:= 1 to 26 do
begin
vect1[i]:= aux[i];
vect2[j]:= aux[j];
vect3[k]:= aux[k];
vect4[l]:= aux[l];
WriteLn (vect1[i],vect2[j],vect3[k],vect4[l]);
Write(Wordlist, vect1[i],vect2[j],vect3[k],vect4[l],' ');
end;
Close(Wordlist);
ReadLn;
end.
When you run the program prints:
aaaa
aaab
aaac
...
zzzx
zzzy
zzzz
Theproblemhereisthatthealgorithmdependsonacounter,whichtakesareasonableamountoftime,sincetheprogramprintseachcombination(from1to1foreachdifferentletter[yyyy;aaab;aaac;etc.]).AsIincreasethenumberofdigitstheprogramtakesmuchlonger.IfIwantacombinationof7digitsforexample(formyaccountstheprogramprints250combinationspersecond)thiswouldtakemorethanayeartohavethesecombinations:
7digits
26possibilitieseach(AtoZ)
8,031,810,176combinationpossibilities
Dividingby250:=32127240,704Seconds
=>535454.01173minutes
=>8924,234hours
=>371days
SearchingalittlemoreIfound,intheresponseofthis Question , and then on other topics, a mention about CROSS JOIN
in SQL.
I would like to elaborate something like this to confront the time the program will take to make the same combinations.
I would like to do it in Pascal, Python or VisuAlg itself (Maybe in C because I'm learning now).