Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Pattern Detection

Ptr_082004Ptr_082004 Member Posts: 31
I have written a piece of code that takes three lines of text and copies
the first matching string to the fourth line. here is an example:

Line 1: "String One with some text"
Line 2: "String two with some more text"
Line 3: "String three with some text"
-----------------------------------------------------------
Line 4: "String "

With the code as it is now it will just copy the word "String" to the
to the fourth line. but I want to copy the words "with some" and "text".

How can I detect all patterns that are greater than 2 chars in more
than 2 strings?

I googled 'Pattern Detection' but didn't find anything
very helpful.

Also I was curious if there is a faster way to multiply by ten than this one:
[code]
mov edx, ebx
shl ebx, 3
lea ebx, [ebx+edx*2]
[/code]
Thanks
Peter

Comments

  • Josh CodeJosh Code Member Posts: 675
    [b][red]This message was edited by Josh Code at 2005-5-18 17:46:31[/red][/b][hr]

    It would be easier if you:
    1. Use a high level language and get the detection tested.
    2. Translate into assembly.

    Detecting a pattern like that is not very easy.
    I'll just give an idea for it. I'm not too confident that it would work but maybe it'll give you some ideas.

    I don't know if this would work but here is an idea for an algorithm:
    [code]

    main algorithm
    inputs: String line[]
    outputs: String []
    begin

    String patterns[]

    pattern[0] = line[0]

    Loop line through lines[1+](let line be each line starting at 1).
    Loop pat through patterns(let pat be each element of patterns)
    begin
    String m = getLargestMatch(line,pat)
    if (pat not equal m.str) then
    begin
    break pat into 2 parts.
    1 being the matched part and 1 being the unmatched part.
    Append the second part to patterns.
    end
    end

    return patterns

    Now patterns is a collection of the longest strings common throughout all lines.
    end

    String getLargestMatch(String line, String pat)
    begin
    String result
    int MaxLen = -1

    Loop through line using index i
    Loop through pat using index p
    if (pat[p] not equal line[i]) then
    begin
    if ((MaxLen<0) or (p>MaxLen)) then
    begin
    MaxLen = p
    result = line[i..i+p] (copy substring)
    end
    Break loop through indexes of pat.
    end
    return result
    end
    [/code]
    If this works, there are ways to optimize it but it is better to be clear than efficient until it works.


    Anyway, hope that helps.

    : I have written a piece of code that takes three lines of text and copies
    : the first matching string to the fourth line. here is an example:
    :
    : Line 1: "String One with some text"
    : Line 2: "String two with some more text"
    : Line 3: "String three with some text"
    : -----------------------------------------------------------
    : Line 4: "String "
    :
    : With the code as it is now it will just copy the word "String" to the
    : to the fourth line. but I want to copy the words "with some" and "text".
    :
    : How can I detect all patterns that are greater than 2 chars in more
    : than 2 strings?
    :
    : I googled 'Pattern Detection' but didn't find anything
    : very helpful.
    :
    : Also I was curious if there is a faster way to multiply by ten than this one:
    : [code]
    : mov edx, ebx
    : shl ebx, 3
    : lea ebx, [ebx+edx*2]
    : [/code]
    : Thanks
    : Peter
    :
    :









Sign In or Register to comment.