Select connected subsets of integer pairs?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
5
down vote

favorite
1












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!










share|improve this question

























    up vote
    5
    down vote

    favorite
    1












    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!










    share|improve this question























      up vote
      5
      down vote

      favorite
      1









      up vote
      5
      down vote

      favorite
      1






      1





      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!










      share|improve this question













      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 4 hours ago









      Kagaratsch

      4,49131246




      4,49131246




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          4
          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







          share|improve this answer





























            up vote
            1
            down vote













            Gather[list, IntersectingQ]



            1, 2, 1, 3, 2, 5, 1, 5,

            6, 7, 6, 9, 4, 6







            share|improve this answer




















              Your Answer





              StackExchange.ifUsing("editor", function ()
              return StackExchange.using("mathjaxEditing", function ()
              StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
              StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
              );
              );
              , "mathjax-editing");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "387"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              convertImagesToLinks: false,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













               

              draft saved


              draft discarded


















              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






























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              4
              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







              share|improve this answer


























                up vote
                4
                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







                share|improve this answer
























                  up vote
                  4
                  down vote



                  accepted







                  up vote
                  4
                  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







                  share|improve this answer














                  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








                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited 4 hours ago

























                  answered 4 hours ago









                  Henrik Schumacher

                  44k263129




                  44k263129




















                      up vote
                      1
                      down vote













                      Gather[list, IntersectingQ]



                      1, 2, 1, 3, 2, 5, 1, 5,

                      6, 7, 6, 9, 4, 6







                      share|improve this answer
























                        up vote
                        1
                        down vote













                        Gather[list, IntersectingQ]



                        1, 2, 1, 3, 2, 5, 1, 5,

                        6, 7, 6, 9, 4, 6







                        share|improve this answer






















                          up vote
                          1
                          down vote










                          up vote
                          1
                          down vote









                          Gather[list, IntersectingQ]



                          1, 2, 1, 3, 2, 5, 1, 5,

                          6, 7, 6, 9, 4, 6







                          share|improve this answer












                          Gather[list, IntersectingQ]



                          1, 2, 1, 3, 2, 5, 1, 5,

                          6, 7, 6, 9, 4, 6








                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered 12 mins ago









                          kglr

                          169k8193396




                          169k8193396



























                               

                              draft saved


                              draft discarded















































                               


                              draft saved


                              draft discarded














                              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













































































                              Comments

                              Popular posts from this blog

                              What does second last employer means? [closed]

                              Installing NextGIS Connect into QGIS 3?

                              One-line joke