Beefy Boxes and Bandwidth Generously Provided by pair Networks DiBona
The stupid question is the question not asked
 
PerlMonks  

Re: finding matches in the same array

by sh1tn (Priest)
on Apr 13, 2005 at 13:28 UTC ( [id://447524]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to finding matches in the same array

@seq = ('acgt','actg','cggt','cggt','actg'); @num = ('1234','2345','3244','3455','5230'); Wrong algorithm #for( 0..$#seq ){ # $struct{$seq[$_]} ||= $num[$_]; # $struct{$seq[$_]} = ($struct{$seq[$_]}+$num[$_]) / 2 #}


Replies are listed 'Best First'.
Re^2: finding matches in the same array
by RazorbladeBidet (Friar) on Apr 13, 2005 at 13:35 UTC
    This gives more weight to the last number (if there are more than 2):
    my @sequence = ('acgt','actg','cggt','cggt', 'actg', 'actg'); my @numbers = ('1234','2345','3244','3455', '5230', '100000' );
    gives 51893.75 when it should be 34526.3333333333
    --------------
    "But what of all those sweet words you spoke in private?"
    "Oh that's just what we call pillow talk, baby, that's all."
      You are right, it's utterly different algorithm.
      The correct one is as follows:
      @seq = ('acgt','actg','cggt','cggt', 'actg', 'actg'); @num = ('1234','2345','3244','3455', '5230', '100000' ); for( 0..$#seq ){ $struct{$seq[$_]}->[0] += $num[$_] and $struct{$seq[$_]}->[1]++ } for( keys %struct ){ print "$_\t", $struct{$_}->[0] / $struct{$_}->[1], $/ } __END__ STDOUT: acgt 1234 cggt 3349.5 actg 35858.3333333333


Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://447524]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.