0
I’m running a four-digit algorithm from A to Z. I did it 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 you print:
aaaa
aaab
aaac
...
zzzx
zzzy
zzzz
The problem here is that the algorithm depends on a counter, which takes a reasonable time, since the program prints each combination (from 1 in 1 for each different letter [aaaa; aaab; aaac; etc.] ). As I increase the number of digits the program takes much longer.
If I wanted a 7-digit combination for example (by my accounts the program prints 250 combinations per second) it would take more than a year to get these combinations:
7 digits
26 possibilities each (A to Z)
8.031.810.176 possible combinations
Divided by 250 := 32127240,704 Seconds
=> 535454,01173 minutes
=> 8924,234 hours
=> 371 days
Researching a little more found, in the answer of this Question, and then on other topics, a mention about CROSS JOIN
in SQL.
I would like to elaborate something of this kind to confront the time it will take the program to make the same combinations.
I would like to do in Pascal, Python or Visualg even (Maybe in C, because I’m learning now).
Probably the delay is in the display, not in the algorithm. Try calculating the time without showing all the combinations on the screen, and see if something changes.
– Bacco
The delay to print on the screen, and not in the file, will be?.
– h1k3r