partition list sets common elements


here's jist problem: given list sets, such as:



[ (1,2,3), (5,2,6), (7,8,9), (6,12,13), (21,8,34), (19,20) ]


return list groups sets, such sets have common component same group.



[ [ (1,2,3), (5,2,6), (6,12,13) ], [ (7,8,9), (21,8,34) ], [ (19,20) ] ]


note stickeyness - set (6,12,13) doesn't have common component (1,2,3), nonetheless put same organisation since (5,2,6).



to thwart matters, i should plead i don't unequivocally have neat sets, nonetheless rather db list several million rows looks like:



element | set_id
----------------
1 | 1
2 | 1
3 | 1
5 | 2
2 | 2
6 | 2


and on. i adore proceed sql, nonetheless i happy whole instruction solution.



edit: altered list buttress names (element, set_id) instead (key, group_id), terms some-more consistent. note kev's answer uses aged buttress names.



Comments

Popular posts from this blog

list macos calm editors formula editors

how hibernate @any-related annotations?

why does floated <input> control floated component slip over too distant right ie7, nonetheless firefox?