Click here to Skip to main content
15,891,567 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
AnswerRe: Factoring ???? Pin
Luc Pattyn8-Mar-11 22:34
sitebuilderLuc Pattyn8-Mar-11 22:34 
GeneralRe: Factoring ???? Pin
Johnkokk8-Mar-11 22:37
Johnkokk8-Mar-11 22:37 
AnswerRe: Factoring ???? Pin
Richard MacCutchan8-Mar-11 23:21
mveRichard MacCutchan8-Mar-11 23:21 
GeneralRe: Factoring ???? Pin
Johnkokk9-Mar-11 0:38
Johnkokk9-Mar-11 0:38 
GeneralRe: Factoring ???? Pin
Richard MacCutchan9-Mar-11 2:26
mveRichard MacCutchan9-Mar-11 2:26 
GeneralRe: Factoring ???? Pin
Johnkokk9-Mar-11 5:37
Johnkokk9-Mar-11 5:37 
GeneralRe: Factoring ???? Pin
Richard MacCutchan9-Mar-11 5:47
mveRichard MacCutchan9-Mar-11 5:47 
AnswerRe: Factoring ???? Pin
Luc Pattyn9-Mar-11 6:17
sitebuilderLuc Pattyn9-Mar-11 6:17 
this is simple when using recursion; what needs to be done is carefully defining the functionality of the recursive method.

Hhere is some pseudo-code that should help:
int[] factors=new int[factorList.Length];

// This method should return true if number can be factored using some factors from factorList
// we assume factorList items are all different, positive, non-zero, and ordered numerically ascending.

// call this method with minimum=0 and nesting=0; when it returns true read factors array till the product matches.

public bool CanBeFactoredWithSomeOfThese(int number, List<int> factorList, int minimum, int nesting) {
    foreach(int factor in factorList) {
        if (factor<=minimum) continue;
        if (number%factor!=0) continue;
        factors[nesting]=factor;
        bool OK=true;
        if (number>factor) OK=CanBeFactoredWithSomeOfThese(number/factor, largerFactors, factor, nesting+1);
        if (OK) return true;
    }
    return false;
}


Although combinations aren't examined more than once (that is what minimum is for, we discover factors in ascending order) and it stops on the first solution, this is not quite optimal as it enumerates the factorList way too much.

Smile | :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

AnswerRe: Factoring ???? Pin
musefan9-Mar-11 4:36
musefan9-Mar-11 4:36 
AnswerRe: Factoring ???? Pin
davidnz20-Mar-11 21:44
davidnz20-Mar-11 21:44 
GeneralRe: Factoring ???? Pin
Johnkokk20-Mar-11 23:07
Johnkokk20-Mar-11 23:07 
GeneralRe: Factoring ???? Pin
davidnz21-Mar-11 12:32
davidnz21-Mar-11 12:32 
QuestionWorkflow or Windows Service??? Pin
Priya Prk7-Mar-11 23:04
Priya Prk7-Mar-11 23:04 
AnswerRe: Workflow or Windows Service??? Pin
mocastro8-Mar-11 3:13
mocastro8-Mar-11 3:13 
AnswerRe: Workflow or Windows Service??? Pin
Abhinav S14-Mar-11 18:07
Abhinav S14-Mar-11 18:07 
QuestionHow can we pick dynamic images and rotate them in J-Query Pin
Andrewnick206-Mar-11 19:35
Andrewnick206-Mar-11 19:35 
AnswerRe: How can we pick dynamic images and rotate them in J-Query Pin
Richard MacCutchan6-Mar-11 22:24
mveRichard MacCutchan6-Mar-11 22:24 
QuestionWindows service with FileSystemWatcher Pin
byka4-Mar-11 5:21
byka4-Mar-11 5:21 
AnswerRe: Windows service with FileSystemWatcher Pin
N a v a n e e t h4-Mar-11 5:30
N a v a n e e t h4-Mar-11 5:30 
GeneralRe: Windows service with FileSystemWatcher Pin
byka4-Mar-11 5:38
byka4-Mar-11 5:38 
GeneralRe: Windows service with FileSystemWatcher Pin
jschell4-Mar-11 7:32
jschell4-Mar-11 7:32 
GeneralRe: Windows service with FileSystemWatcher Pin
Eddy Vluggen4-Mar-11 12:23
professionalEddy Vluggen4-Mar-11 12:23 
AnswerRe: Windows service with FileSystemWatcher Pin
Bernhard Hiller7-Mar-11 20:31
Bernhard Hiller7-Mar-11 20:31 
QuestionConnecting SQL server 2008 to Visual studio 2008 Pin
MahaKh3-Mar-11 19:02
MahaKh3-Mar-11 19:02 
AnswerRe: Connecting SQL server 2008 to Visual studio 2008 PinPopular
Roger Wright3-Mar-11 19:47
professionalRoger Wright3-Mar-11 19:47 

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.