Home
Top.Mail.Ru Yandeks.Metrika
Forum: "Main";
Current archive: 2002.01.08;
Download: [xml.tar.bz2];

Down

Rather a mathematical question ... Find similar branches


Дмитрий Д.   (2001-12-17 13:28) [0]

Does anyone tell me the algorithm for obtaining all possible values ​​composed of array elements (for example, 3x3):

qwe
asd
zxc

that is, result may be for the first line:
qwe
qwd
qwc
qse
qsd
Qsc

and so on ...
The algorithm itself is important, because the values ​​of the array can be either letters or whole words

Thank you in advance.



Виктор Щербаков   (2001-12-17 13:33) [1]

Three nested loops. One on the first column, another on the second, third on the third. What is the problem?



Дмитрий Д.   (2001-12-17 13:42) [2]

It's clear
the problem is I have a number of both rows and columns can be different ...
(I took 3x3 for example)
therefore, we need an algorithm



Виктор Щербаков   (2001-12-17 13:46) [3]

Then recursive iteration:
The function calls itself, passing in quality. parameter column number of the array. And so on until it reaches the last column (or the first). In the function itself, we get a single column loop.



Дмитрий Д.   (2001-12-17 13:59) [4]

and a piece of code is possible?
I thought about recursion, but I just can’t figure it out



Виктор Щербаков   (2001-12-17 14:11) [5]

Something like this (whipped up).
The array itself is filled with what you need.

procedure TForm1.Button2Click (Sender: TObject); var a: array [1..3, 1..3] of char; CurLine: String; procedure Proc1 (Col: Integer); var i: Integer; begin for i: = 1 to 3 do begin if Col = 0 then begin Memo1.Lines.Add (CurLine); exit end; CurLine: = CurLine + a [i, col]; proc1 (Col - 1); SetLength (CurLine, Length (CurLine) - 1); end; end; begin CurLine: = ""; proc1 (3); end;




Pages: 1 whole branch

Forum: "Main";
Current archive: 2002.01.08;
Download: [xml.tar.bz2];

Top









Memory: 0.56 MB
Time: 0.023 c
We answer immediately.
KLM
2001-09-20 06:34
2002.01.08
Copy protection


We answer immediately.
Sergei N.
2001-12-04 06:23
2002.01.08
Handling dates from IB to Delphi and back


We answer immediately.
Serge
2001-12-18 19:18
2002.01.08
Deleting an object


We answer immediately.
Nathan
2001-12-21 11:07
2002.01.08
Problem!


We answer immediately.
olban
2001-12-05 11:07
2002.01.08
Use QuantumGrid





afrikaans albanian Arabic armenian azerbaijani basque belarusian bulgarian catalan Chinese (Simplified) Chinese (Traditional) croatian Czech danish Dutch English estonian filipino finnish French
galician georgian German greek haitian Creole hebrew Hindi hungarian icelandic indonesian Irish italian japanese Korean latvian lithuanian macedonian malay maltese norwegian
persian polish portuguese Romanian russian serbian slovak Slovenian Español swahili Swedish thai turkish Ukrainian urdu vietnamese welsh yiddish bengali bosnian
cebuano Esperanto gujarati hausa hmong igbo javanese kannada khmer lao latin maori marathi mongolian nepali punjabi somali tamil telugu yoruba
zulu
English French German Italian Portuguese Russian Spanish