Click here to Skip to main content
16,018,525 members
Home / Discussions / C#
   

C#

 
GeneralRe: save & open file... Pin
Christian Graus25-Apr-07 15:14
protectorChristian Graus25-Apr-07 15:14 
GeneralRe: save & open file... Pin
mr jets25-Apr-07 15:19
mr jets25-Apr-07 15:19 
GeneralRe: save & open file... Pin
mr jets25-Apr-07 16:21
mr jets25-Apr-07 16:21 
QuestionInteger/Decimal control in Windows Froms Pin
Nooie25-Apr-07 13:59
Nooie25-Apr-07 13:59 
AnswerRe: Integer/Decimal control in Windows Froms Pin
Christian Graus25-Apr-07 14:21
protectorChristian Graus25-Apr-07 14:21 
QuestionCombinations or Permutations or something else?? Pin
allenmpcx25-Apr-07 12:18
allenmpcx25-Apr-07 12:18 
AnswerRe: Combinations or Permutations or something else?? Pin
Arun.Immanuel25-Apr-07 15:08
Arun.Immanuel25-Apr-07 15:08 
AnswerRe: Combinations or Permutations or something else?? [modified] Pin
Luc Pattyn25-Apr-07 15:52
sitebuilderLuc Pattyn25-Apr-07 15:52 
Hi,

there is at least one way to generate the strings you want without trying more
combinations and then rejecting the ones that dont fit the constraints.

Lets say we want all the strings containing M ones and M zeroes.

Assume a recursive method that at each level generates zero to MAX zeroes
followed by a single one (hence MAX+1 different strings). If we call this methods
M times (concatenating the output of each recursion level), we will get M ones
and some number of zeroes. By carefully calculating
MAX on each level, we can get exactly M zeroes as well.

So initially MAX equals M. If fewer than M recursions have been executed, recurse
with MAX reduced by the amount of zeroes already emitted; also after M recursions
add the missing zeroes if any.

So for M=2 it would generate in order:
001  1    /
01   01   /
01   1    0
1    001  /
1    01   0
1    1    00

where the first column holds the output of the first level, the second the output
of the second level of recursion, and the third column the added missing zeroes.

When the sequence of zeroes in each level is generated from MAX downto zero zeroes,
the net result is the numbers appear in numerical order.

No trial and error involved !


BTW this is not a C# question at all, it would fit better in math & algos forum !

Smile | :)







-- modified at 21:57 Wednesday 25th April, 2007

Luc Pattyn

[My Articles]

GeneralRe: Combinations or Permutations or something else?? Pin
Arun.Immanuel25-Apr-07 16:09
Arun.Immanuel25-Apr-07 16:09 
Questionsolution urgent please Pin
netJP12L25-Apr-07 12:11
netJP12L25-Apr-07 12:11 
AnswerRe: solution urgent please Pin
Colin Angus Mackay25-Apr-07 21:22
Colin Angus Mackay25-Apr-07 21:22 
GeneralRe: solution urgent please Pin
netJP12L26-Apr-07 8:48
netJP12L26-Apr-07 8:48 
QuestionHiding the UI Pin
AAKAra25-Apr-07 12:04
AAKAra25-Apr-07 12:04 
AnswerRe: Hiding the UI Pin
caix25-Apr-07 15:19
caix25-Apr-07 15:19 
GeneralRe: Hiding the UI Pin
AAKAra27-Apr-07 4:12
AAKAra27-Apr-07 4:12 
GeneralRe: Hiding the UI [modified] Pin
caix29-Apr-07 13:44
caix29-Apr-07 13:44 
Questionanother windows form questions Pin
MarkSchultz25-Apr-07 11:44
MarkSchultz25-Apr-07 11:44 
AnswerRe: another windows form questions Pin
Rocky#25-Apr-07 22:22
Rocky#25-Apr-07 22:22 
Questiondrag drop operations between 2 listboxes Pin
rzvme25-Apr-07 8:53
rzvme25-Apr-07 8:53 
AnswerRe: drag drop operations between 2 listboxes Pin
Paul Conrad25-Apr-07 9:48
professionalPaul Conrad25-Apr-07 9:48 
AnswerRe: drag drop operations between 2 listboxes Pin
Dan Neely25-Apr-07 10:27
Dan Neely25-Apr-07 10:27 
GeneralRe: drag drop operations between 2 listboxes Pin
Paul Conrad25-Apr-07 10:56
professionalPaul Conrad25-Apr-07 10:56 
Questionproblem with passing method to thread class. Pin
hdv21225-Apr-07 8:39
hdv21225-Apr-07 8:39 
AnswerRe: problem with passing method to thread class. Pin
Tarakeshwar Reddy25-Apr-07 8:53
professionalTarakeshwar Reddy25-Apr-07 8:53 
AnswerRe: problem with passing method to thread class. Pin
Jimmanuel25-Apr-07 9:11
Jimmanuel25-Apr-07 9:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.