Select connected subsets of integer pairs?
Clash Royale CLAN TAG#URR8PPP
up vote
4
down vote
favorite
Given a list of integer pairs such as
list = 1,2,1,3,2,5,1,5,6,7,6,9,4,6 ;
What is a quick way to separate the pairs into groups in which every element shares at least one integer with at least one other element, in Mathematica? e.g.:
separate[list]
1,2,1,3,2,5,1,5 , 6,7,6,9,4,6
Thanks for any suggestion!
list-manipulation function-construction
add a comment |Â
up vote
4
down vote
favorite
Given a list of integer pairs such as
list = 1,2,1,3,2,5,1,5,6,7,6,9,4,6 ;
What is a quick way to separate the pairs into groups in which every element shares at least one integer with at least one other element, in Mathematica? e.g.:
separate[list]
1,2,1,3,2,5,1,5 , 6,7,6,9,4,6
Thanks for any suggestion!
list-manipulation function-construction
add a comment |Â
up vote
4
down vote
favorite
up vote
4
down vote
favorite
Given a list of integer pairs such as
list = 1,2,1,3,2,5,1,5,6,7,6,9,4,6 ;
What is a quick way to separate the pairs into groups in which every element shares at least one integer with at least one other element, in Mathematica? e.g.:
separate[list]
1,2,1,3,2,5,1,5 , 6,7,6,9,4,6
Thanks for any suggestion!
list-manipulation function-construction
Given a list of integer pairs such as
list = 1,2,1,3,2,5,1,5,6,7,6,9,4,6 ;
What is a quick way to separate the pairs into groups in which every element shares at least one integer with at least one other element, in Mathematica? e.g.:
separate[list]
1,2,1,3,2,5,1,5 , 6,7,6,9,4,6
Thanks for any suggestion!
list-manipulation function-construction
list-manipulation function-construction
asked 4 hours ago
Kagaratsch
4,48631246
4,48631246
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
3
down vote
accepted
G = Graph[1, 2, 1, 3, 2, 5, 1, 5, 6, 7, 6, 9, 4, 6];
Select[
List @@@ EdgeList[Subgraph[G, #]] & /@ ConnectedComponents[G],
Length[#]>0 &
]
4, 6, 6, 7, 6, 9, 1, 2, 1, 3, 2, 5, 1, 5
add a comment |Â
up vote
0
down vote
Gather[list, IntersectingQ]
1, 2, 1, 3, 2, 5, 1, 5,
6, 7, 6, 9, 4, 6
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
G = Graph[1, 2, 1, 3, 2, 5, 1, 5, 6, 7, 6, 9, 4, 6];
Select[
List @@@ EdgeList[Subgraph[G, #]] & /@ ConnectedComponents[G],
Length[#]>0 &
]
4, 6, 6, 7, 6, 9, 1, 2, 1, 3, 2, 5, 1, 5
add a comment |Â
up vote
3
down vote
accepted
G = Graph[1, 2, 1, 3, 2, 5, 1, 5, 6, 7, 6, 9, 4, 6];
Select[
List @@@ EdgeList[Subgraph[G, #]] & /@ ConnectedComponents[G],
Length[#]>0 &
]
4, 6, 6, 7, 6, 9, 1, 2, 1, 3, 2, 5, 1, 5
add a comment |Â
up vote
3
down vote
accepted
up vote
3
down vote
accepted
G = Graph[1, 2, 1, 3, 2, 5, 1, 5, 6, 7, 6, 9, 4, 6];
Select[
List @@@ EdgeList[Subgraph[G, #]] & /@ ConnectedComponents[G],
Length[#]>0 &
]
4, 6, 6, 7, 6, 9, 1, 2, 1, 3, 2, 5, 1, 5
G = Graph[1, 2, 1, 3, 2, 5, 1, 5, 6, 7, 6, 9, 4, 6];
Select[
List @@@ EdgeList[Subgraph[G, #]] & /@ ConnectedComponents[G],
Length[#]>0 &
]
4, 6, 6, 7, 6, 9, 1, 2, 1, 3, 2, 5, 1, 5
edited 4 hours ago
answered 4 hours ago
Henrik Schumacher
44k263129
44k263129
add a comment |Â
add a comment |Â
up vote
0
down vote
Gather[list, IntersectingQ]
1, 2, 1, 3, 2, 5, 1, 5,
6, 7, 6, 9, 4, 6
add a comment |Â
up vote
0
down vote
Gather[list, IntersectingQ]
1, 2, 1, 3, 2, 5, 1, 5,
6, 7, 6, 9, 4, 6
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Gather[list, IntersectingQ]
1, 2, 1, 3, 2, 5, 1, 5,
6, 7, 6, 9, 4, 6
Gather[list, IntersectingQ]
1, 2, 1, 3, 2, 5, 1, 5,
6, 7, 6, 9, 4, 6
answered 7 mins ago
kglr
169k8193396
169k8193396
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f185448%2fselect-connected-subsets-of-integer-pairs%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password