menth0l has asked for the wisdom of the Perl Monks concerning the following question:
I have a problem with "translating" this to perl. I know I need some kind of map for storing information about valid pairs and their id (like python's map of tuples: (x,y) => z). But having two sets, each consisting of 100 elements requires 100x100=10000 combinations... Is there any quicker method for this?# subset 1 of (A..Z) set_1 = (A, B, C, X, Y, Z) # subset 2 of (a..z) set_2 = (q, w, r, t, u) # valid pairs valid = ((A,q) = 1, (A,u) = 6, (A,k) => 3, (C,t) = 10, (Z,u) = 30)
I could narrow search by creating intersection (e.g. using Set::Object):my %INDEX = { A => { q => 1, u => 6, k => 3 }, C => { t => 10 }, Z => { u => 30 }, M => { q => 100 } }
then i would be left with an array of hash-refs and do:# narrow by first set (set_1) x (keys %INDEX) = (set_1) x (A, C, M, Z) = (A, C, Z)
set_2 x (q, u, k) + set_2 x (t) + set_2 x (u) = (1, 6, 10, 30)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Two dimensional sets intersection
by daxim (Curate) on Apr 10, 2013 at 13:28 UTC | |
|
Re: Two dimensional sets intersection
by Not_a_Number (Prior) on Apr 10, 2013 at 20:44 UTC | |
|
Re: Two dimensional sets intersection
by LanX (Saint) on Apr 10, 2013 at 14:29 UTC |