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.55 MB
Time: 0.044 c
3-21942
Rev
2001-12-03 12:19
2002.01.08
Good people help with the stored procedure.


14-22332
Noname (Andrews)
2001-11-05 16:20
2002.01.08
Moderator HELP !!!


14-22397
dead
2001-11-10 18:49
2002.01.08
Does anyone have a gif or jpg contour map of the world?


3-21981
Termik
2001-12-06 08:22
2002.01.08
About key fields and IDENTITY


1-22159
Phisio
2001-12-19 22:56
2002.01.08
How to create a new structure





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 Spanish 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