Click here to Skip to main content
15,897,291 members
Home / Discussions / Algorithms
   

Algorithms

 
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 
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 
If you will check several values of Z per session, and memory usage is not a problem, you might store the work of the algorithm as you check for a value of Z. Errr... confusing, It's hard for me to explain this in English. Let me give you an example in C#:

C#
public class Solutions
{
    Dictionary<int, bool> matches = new Dictionary<int, bool>();
    int maxZ = 0;

    public bool? EvenSolutions(int z)
    {
        if (z > maxZ)
        {
            int maxY = (int)Math.Sqrt(z - 3);
            int maxX = (int)(Math.Sqrt(z - 1 / 3d));
            int n = 4;

            for (int x = 1; x < maxX; x++)
            {
                for (int y = 1; y < maxY && (n = 3 * x * x + y * y) <= z; y++)
                {
                    if (n > maxZ)
                    {
                        if (!matches.ContainsKey(n))
                            matches.Add(n, false);
                        else
                            matches[n] = !matches[n];
                    }
                }
            }

            maxZ = z;
        }

        return (matches.ContainsKey(z)) ? (bool?)matches[z] : null;
    }
}


The method returns true if there is a even number of solutions; false if the number of solutions is odd; and null if there are no solutions but, at the same time, it stores the possible values of Z which have solutions and are lesser than the given Z. So, if you are later checking for a smaller value of Z, you will already have it in matches dictionary and you will not have to repeat the process... and if it is not in the dictionary then it means that there weren't solutions for that value of Z.
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 
AnswerRe: TIL...... Pin
Richard MacCutchan4-Nov-10 2:46
mveRichard MacCutchan4-Nov-10 2:46 
GeneralRe: TIL...... Pin
NeverHeardOfMe4-Nov-10 2:57
NeverHeardOfMe4-Nov-10 2:57 
GeneralRe: TIL...... Pin
Richard MacCutchan4-Nov-10 3:24
mveRichard MacCutchan4-Nov-10 3:24 
GeneralRe: TIL...... Pin
NeverHeardOfMe4-Nov-10 3:28
NeverHeardOfMe4-Nov-10 3:28 

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.