Click here to Skip to main content
15,891,253 members
Home / Discussions / Algorithms
   

Algorithms

 
GeneralRe: Patterns Pin
Jörgen Sigvardsson2-Aug-07 21:15
Jörgen Sigvardsson2-Aug-07 21:15 
GeneralRe: Patterns Pin
Paul Conrad3-Aug-07 3:34
professionalPaul Conrad3-Aug-07 3:34 
GeneralRe: Patterns Pin
Jörgen Sigvardsson3-Aug-07 3:41
Jörgen Sigvardsson3-Aug-07 3:41 
GeneralRe: Patterns Pin
Malcolm Smart11-Aug-07 10:19
Malcolm Smart11-Aug-07 10:19 
GeneralRe: Patterns Pin
Paul Conrad11-Aug-07 10:28
professionalPaul Conrad11-Aug-07 10:28 
AnswerRe: Patterns Pin
Stephen Hewitt29-Jul-07 15:41
Stephen Hewitt29-Jul-07 15:41 
GeneralRe: Patterns Pin
Paul Conrad29-Jul-07 17:36
professionalPaul Conrad29-Jul-07 17:36 
AnswerRe: Patterns Pin
Luc Pattyn29-Jul-07 23:56
sitebuilderLuc Pattyn29-Jul-07 23:56 
Hi,

this could be very easy, depends on your definition of pattern.

if your example 236321236 contains two patterns for you, that is 23 (twice),
then the following will do. If the fact that 236 appears twice is a pattern too,
then it is harder.

Here is my algorithm in pseudo-code (i.e. approx C#); some details may
be incorrect, but you will get the general idea; it is quadratic which
is good enough for phone numbers I guess.

string s="my text to analyze";
int sLength=s.Length;
for (int i=0; i<sLength-1; i++) {
    char c1=s[i];
    char c2=s[i+1];
    int diff=c2-c1;
    if (diff==0) log("double char");
    if (diff*diff==1) log("two char series");
    for (int len=3; len<sLength-i; len++) {  // for 3d, 4th, ... char in candidate
        c2+=diff;
        char c=s[i+len-1];
        if (c2==c) log("series extends to "+len+" chars");
        else break;
    }
}


As you can see, nothing fancy, no tricks, no regex...
Smile | :)










QuestionPrimality Test Pin
shiraztk27-Jul-07 7:47
shiraztk27-Jul-07 7:47 
AnswerRe: Primality Test Pin
Paul Conrad27-Jul-07 8:17
professionalPaul Conrad27-Jul-07 8:17 
AnswerRe: Primality Test Pin
cp987627-Jul-07 11:40
cp987627-Jul-07 11:40 
GeneralRe: Primality Test Pin
Paul Conrad27-Jul-07 19:50
professionalPaul Conrad27-Jul-07 19:50 
GeneralRe: Primality Test Pin
shiraztk30-Jul-07 7:31
shiraztk30-Jul-07 7:31 
GeneralRe: Primality Test Pin
Paul Conrad30-Jul-07 10:52
professionalPaul Conrad30-Jul-07 10:52 
GeneralRe: Primality Test Pin
cp987630-Jul-07 23:53
cp987630-Jul-07 23:53 
GeneralRe: Primality Test Pin
Gyan Prakash8-Aug-07 22:00
Gyan Prakash8-Aug-07 22:00 
AnswerRe: Primality Test Pin
Gyan Prakash8-Aug-07 21:55
Gyan Prakash8-Aug-07 21:55 
QuestionMagics of 4 Pin
shiraztk26-Jul-07 8:49
shiraztk26-Jul-07 8:49 
AnswerRe: Magics of 4 Pin
Maximilien26-Jul-07 9:27
Maximilien26-Jul-07 9:27 
AnswerRe: Magics of 4 Pin
David Crow26-Jul-07 10:50
David Crow26-Jul-07 10:50 
AnswerRe: Magics of 4 Pin
CPallini26-Jul-07 12:18
mveCPallini26-Jul-07 12:18 
AnswerRe: Magics of 4 Pin
cp987626-Jul-07 13:32
cp987626-Jul-07 13:32 
GeneralRe: Magics of 4 Pin
shiraztk27-Jul-07 4:00
shiraztk27-Jul-07 4:00 
GeneralRe: Magics of 4 Pin
Paul Conrad27-Jul-07 19:50
professionalPaul Conrad27-Jul-07 19:50 
QuestionLinear line Pin
flippydeflippydebop25-Jul-07 9:15
flippydeflippydebop25-Jul-07 9:15 

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.