Algorithm with HoA looping

P

PB0711

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 :)
 
D

Dr.Ruud

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"
 
P

PB0711

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,
 
U

usenet

PB0711 said:
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 } ],
],
);
 
P

PB0711

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,
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top