Algorithm with HoA looping

Discussion in 'Perl Misc' started by PB0711, Nov 11, 2006.

  1. PB0711

    PB0711 Guest

    Hello,

    I need some help designing an algorithm to loop thought a HoA a user
    defined number of times. I want to take the keys and make every
    possible combination of the keys. Then take all of this and put it into
    a database. The DB will then contain the combinations of the keys and
    the additions of the values (the array) as the data for each key
    combinatiion. I hope that makes sense. Any help would be great.

    Cheers,

    PB :)
     
    PB0711, Nov 11, 2006
    #1
    1. Advertising

  2. PB0711

    Dr.Ruud Guest

    PB0711 schreef:

    > I need some help designing an algorithm to loop thought a HoA a user
    > defined number of times. I want to take the keys and make every
    > possible combination of the keys. Then take all of this and put it
    > into a database. The DB will then contain the combinations of the
    > keys and the additions of the values (the array) as the data for each
    > key combinatiion. I hope that makes sense. Any help would be great.



    Where is your code?


    Suppose your hash is

    %HoA = ( a => [1, 2, 3]
    , b => [4, 5, 6]
    , c => [7, 8, 9]
    ) ;

    then should a query limited by "a,c,b" return 6+24+15= 45?


    The table can then just hold

    a,6
    b,15
    c,24

    and you can leave the summing to the database, something like

    SELECT SUM(sum_array) AS tot FROM table WHERE key IN "a,c,b"

    --
    Affijn, Ruud

    "Gewoon is een tijger."
     
    Dr.Ruud, Nov 12, 2006
    #2
    1. Advertising

  3. PB0711

    PB0711 Guest

    > Suppose your hash is
    >
    > %HoA = ( a => [1, 2, 3]
    > , b => [4, 5, 6]
    > , c => [7, 8, 9]
    > ) ;
    >
    > then should a query limited by "a,c,b" return 6+24+15= 45?
    >
    >
    > The table can then just hold
    >
    > a,6
    > b,15
    > c,24
    >
    > and you can leave the summing to the database, something like
    >
    > SELECT SUM(sum_array) AS tot FROM table WHERE key IN "a,c,b"


    Sorry I haven't made any code yet, but I should have done a better job
    at explaining it. So what I have are 20 things each of these 20 things
    have data attached to itself.So
    A => location, size, a text image
    B => location, size, text image
    C => ....
    and so on.
    So I wan to take every possible combination. So I would have AB, BA,
    AC, CA, CB, BC. Then I would the arrays and alter them so they are
    added together. So I will have 20^2.
    I think I need some kind of recursive function, yes?

    Cheers again,
     
    PB0711, Nov 13, 2006
    #3
  4. PB0711

    Guest

    PB0711 wrote:
    > So I wan to take every possible combination. So I would have AB, BA,
    > AC, CA, CB, BC. Then I would the arrays and alter them so they are
    > added together.


    What do you get when you "add" locations together? Give us an example
    of what your input data looks like, and what you want your output data
    to look like.

    For example, your input data might look like:

    ( a => [ qw{ Seattle 6 image1.jpg } ],
    b => [ qw{ Portland 3 image2.jpg } ],
    c => [ qw{ Atlanta 4 image3.jpg } ],
    );

    and you want your output data to look like:

    (ab => [ [ qw{ Seattle Portland } ],
    [ 6, 3 ],
    [ qw{ image1.jpg image2.jpg } ],
    ],
    ac => [ [ qw{ Seattle Atlanta } ],
    [ 6, 4 ],
    [ qw{ image1.jpg image3.jpg } ],
    ],
    );

    --
    The best way to get a good answer is to ask a good question.
    David Filmer (http://DavidFilmer.com)
     
    , Nov 13, 2006
    #4
  5. PB0711

    PB0711 Guest

    So, I have found a very good module on cpan.
    I'm dealing with amino acids so my data looks like
    A => mass, formula, structure
    T...
    V....
    S....
    all 20 Amino acids

    I have sorted out my looping problem with a nice extra counter in my
    loops. I'll put the code up when I finish, or pseudo code.

    thanks for the help thou,
     
    PB0711, Nov 14, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ahmed Moustafa
    Replies:
    0
    Views:
    796
    Ahmed Moustafa
    Nov 15, 2003
  2. Bapaiah Katepalli
    Replies:
    1
    Views:
    1,512
    Mike Treseler
    Jun 23, 2006
  3. PB0711

    HOA redundancy in array.

    PB0711, Aug 8, 2006, in forum: Perl Misc
    Replies:
    6
    Views:
    110
    Ben Morrow
    Aug 8, 2006
  4. PB0711

    HoA bug? Size limit?

    PB0711, Nov 18, 2006, in forum: Perl Misc
    Replies:
    7
    Views:
    233
    PB0711
    Nov 18, 2006
  5. Replies:
    5
    Views:
    288
Loading...

Share This Page