Velocity Reviews > Perl > Algorithm with HoA looping

# Algorithm with HoA looping

PB0711
Guest
Posts: n/a

 11-11-2006
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

Dr.Ruud
Guest
Posts: n/a

 11-12-2006
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.

%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."

PB0711
Guest
Posts: n/a

 11-13-2006
>
> %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,

usenet@DavidFilmer.com
Guest
Posts: n/a

 11-13-2006
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

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)

PB0711
Guest
Posts: n/a

 11-14-2006
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,