Click here to Skip to main content
15,895,799 members
Home / Discussions / Algorithms
   

Algorithms

 
AnswerRe: I'm Looking For An Algorithm To Optimize Keno Selections Pin
trooper081423-Dec-10 20:28
trooper081423-Dec-10 20:28 
AnswerRe: I'm Looking For An Algorithm To Optimize Keno Selections Pin
Mwanzia_M21-Jan-11 3:05
Mwanzia_M21-Jan-11 3:05 
GeneralRe: I'm Looking For An Algorithm To Optimize Keno Selections Pin
Roger Wright21-Jan-11 17:06
professionalRoger Wright21-Jan-11 17:06 
QuestionOpenSource Audio DSP Algorithms/Filters? Pin
Yuval Naveh10-Dec-10 7:40
Yuval Naveh10-Dec-10 7:40 
AnswerRe: OpenSource Audio DSP Algorithms/Filters? Pin
TweakBird22-Dec-10 20:05
TweakBird22-Dec-10 20:05 
GeneralRe: OpenSource Audio DSP Algorithms/Filters? Pin
Yuval Naveh22-Dec-10 23:25
Yuval Naveh22-Dec-10 23:25 
QuestionNumber of Integer Solutions to an Equation Pin
Skippums23-Nov-10 15:03
Skippums23-Nov-10 15:03 
AnswerRe: Number of Integer Solutions to an Equation PinPopular
Sauro Viti24-Nov-10 0:19
professionalSauro Viti24-Nov-10 0:19 
Let's rewrite your equation as y2 = z - 3x2. Then y = sqrt(z - 3x2).

We can easily see that there are no solutions for z < 3. Now we can write the following code (is C code, but it's easy to port it to another language):

int f(int z)
{
   int result = 0;
   int x = 0;
   double m = 0; // m is 3*x*x
   double y;

   if (z < 3) return 0; // You could remove this line (the function will continue to work properly)

   while (m <= z)
   {
      y = sqrt(z - m);

      // Test if y is integer...
      if (y == floor(y)) result++;

      x++;
      m = 3*x*x;
   }

   return result;
}


Note that this function has a complexity of O(z-2) as it checks for all possible integers values of x.
Also note that this implementation accept solutions where x and/or y are zero (e.g. f(4) returns 2 and the solutions found are { 0, 2 } and { 1 ,1 }). If you want solutions with x and y stricly positive you should initialize the loop with x = 1 and m = 3, and inside the loop ignore solutions with y == 0.
AnswerRe: Number of Integer Solutions to an Equation Pin
Luc Pattyn24-Nov-10 3:56
sitebuilderLuc Pattyn24-Nov-10 3:56 
GeneralRe: Number of Integer Solutions to an Equation Pin
Skippums24-Nov-10 4:26
Skippums24-Nov-10 4:26 
AnswerRe: Number of Integer Solutions to an Equation Pin
Luc Pattyn24-Nov-10 4:47
sitebuilderLuc Pattyn24-Nov-10 4:47 
GeneralRe: Number of Integer Solutions to an Equation Pin
_Erik_24-Nov-10 6:00
_Erik_24-Nov-10 6:00 
AnswerRe: Number of Integer Solutions to an Equation [modified] Pin
Alain Rist26-Nov-10 1:50
Alain Rist26-Nov-10 1:50 
Questionfind lower bound Pin
liquid_18-Nov-10 6:11
liquid_18-Nov-10 6:11 
AnswerRe: find lower bound Pin
NeverHeardOfMe18-Nov-10 6:22
NeverHeardOfMe18-Nov-10 6:22 
GeneralRe: find lower bound Pin
liquid_18-Nov-10 20:25
liquid_18-Nov-10 20:25 
GeneralRe: find lower bound Pin
NeverHeardOfMe18-Nov-10 21:49
NeverHeardOfMe18-Nov-10 21:49 
GeneralRe: find lower bound Pin
harold aptroot18-Nov-10 21:35
harold aptroot18-Nov-10 21:35 
AnswerRe: find lower bound Pin
Alain Rist18-Nov-10 23:24
Alain Rist18-Nov-10 23:24 
GeneralRe: find lower bound Pin
liquid_20-Nov-10 11:32
liquid_20-Nov-10 11:32 
GeneralRe: find lower bound Pin
Alain Rist20-Nov-10 20:04
Alain Rist20-Nov-10 20:04 
GeneralRe: find lower bound Pin
liquid_21-Nov-10 5:09
liquid_21-Nov-10 5:09 
QuestionTIL...... [modified] Pin
NeverHeardOfMe3-Nov-10 23:57
NeverHeardOfMe3-Nov-10 23:57 
AnswerRe: TIL...... Pin
Radhakrishnan G.4-Nov-10 1:40
Radhakrishnan G.4-Nov-10 1:40 
GeneralRe: TIL...... Pin
NeverHeardOfMe4-Nov-10 2:38
NeverHeardOfMe4-Nov-10 2:38 

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.