Re: data analysis

new topic     » goto parent     » topic index » view thread      » older message » newer message

At 08:51 PM 15/01/01 -0800, you wrote:
>I am trying to look at a set amount of data and figure out a repeting data
>pattern, any idea where i can get some routiens that already do this? None
>of mine work =(
>
>
>
>J Reeves
>Grape Vine



if I understand the question correctly, this should help.


It copies dat to s then searches s for characters.
if it isn't a pattern, the found character is erased
in s (by adding one to it) then it searches again.
dat is preserved to test for patterns.

This could be optimised by shortening s for subsequent searches.

It still needs some checking, passing it the wrong sequence
will crash it with a 'slice ends past seq end' error, but
it should get you of on the right foot.

Graeme




function get_pattern(sequence dat)
    integer f
    sequence s,test

    s=dat
    s[1]+=1
    while 1 do

        f=find(dat[1],s)
        if not f then
            return "No Pattern"
        end if

        if equal(dat[1..f-1],dat[f..f*2-2]) then
            test=dat[1..f-1]
            for x=1 to floor(length(dat)/length(test))+1 do
                test&=dat[1..f-1]
            end for
            if equal(test[1..length(dat)],dat) then
                return dat[1..f-1]
            end if
            s[f]+=1
        else
            s[f]+=1
        end if

    end while
end function




puts(1,get_pattern("asdfasdfasdfasdf")&"\n")
puts(1,get_pattern("aaajaaajaaajaaaj")&"\n")
puts(1,get_pattern("efvineifvuhdsdfsdf")&"\n")


----------------------------------------------------

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu