All possible ways to split a number












0












$begingroup$


I am trying to find a way to find (if it is possible) how many ways there are to split a number of n digits considering that the "splits" can occur everywhere and the subsets don't have to be the same length. So for example, if I have a 5 digits number "12345" I can split it into 16(?) ways:



1)12345



2)1-2-3-4-5



3)1-2345



4)12-345



5)123-45



6)1-23-45 etc.



So I am looking for all possible strategies to split the number. I am looking for both a formula and an algorithm. I am guessing that it is 2^(n-1) but I am not sure and I'd like to know why, if this is the case










share|cite|improve this question









$endgroup$

















    0












    $begingroup$


    I am trying to find a way to find (if it is possible) how many ways there are to split a number of n digits considering that the "splits" can occur everywhere and the subsets don't have to be the same length. So for example, if I have a 5 digits number "12345" I can split it into 16(?) ways:



    1)12345



    2)1-2-3-4-5



    3)1-2345



    4)12-345



    5)123-45



    6)1-23-45 etc.



    So I am looking for all possible strategies to split the number. I am looking for both a formula and an algorithm. I am guessing that it is 2^(n-1) but I am not sure and I'd like to know why, if this is the case










    share|cite|improve this question









    $endgroup$















      0












      0








      0





      $begingroup$


      I am trying to find a way to find (if it is possible) how many ways there are to split a number of n digits considering that the "splits" can occur everywhere and the subsets don't have to be the same length. So for example, if I have a 5 digits number "12345" I can split it into 16(?) ways:



      1)12345



      2)1-2-3-4-5



      3)1-2345



      4)12-345



      5)123-45



      6)1-23-45 etc.



      So I am looking for all possible strategies to split the number. I am looking for both a formula and an algorithm. I am guessing that it is 2^(n-1) but I am not sure and I'd like to know why, if this is the case










      share|cite|improve this question









      $endgroup$




      I am trying to find a way to find (if it is possible) how many ways there are to split a number of n digits considering that the "splits" can occur everywhere and the subsets don't have to be the same length. So for example, if I have a 5 digits number "12345" I can split it into 16(?) ways:



      1)12345



      2)1-2-3-4-5



      3)1-2345



      4)12-345



      5)123-45



      6)1-23-45 etc.



      So I am looking for all possible strategies to split the number. I am looking for both a formula and an algorithm. I am guessing that it is 2^(n-1) but I am not sure and I'd like to know why, if this is the case







      combinatorics algorithms combinations






      share|cite|improve this question













      share|cite|improve this question











      share|cite|improve this question




      share|cite|improve this question










      asked Dec 8 '18 at 16:38









      Craig MontevecchiCraig Montevecchi

      447




      447






















          3 Answers
          3






          active

          oldest

          votes


















          1












          $begingroup$

          Your problem can be solved using permutation with repetition in general.



          Permutations with repetition



          Ordered arrangements of the elements of a set S of length n where repetition is allowed are called n-tuples, but have sometimes been referred to as permutations with repetition although they are not permutations in general. They are also called words over the alphabet S in some contexts. If the set S has k elements, the number of n-tuples over S is:



          The general formula is $ k^n $ where $k$ is the number of elements of S and $n$ the length of the tuple to form.



          There is no restriction on how often an element can appear in an n-tuple, but if restrictions are placed on how often an element can appear, this formula is no longer valid.



          In particular your problem to split 5 figures is equivalent to arrange 4 elements ($n=4$) from a set S of 2 elements ($k=2$) i.e.



          ${"-", "Nothing"}$



          in order to get 4 tuples;



          $("-/Nothing","-/Nothing","-/Nothing","-/Nothing")$ where slash $/$ means logical operator "or".



          Therefore you will get the amount that you have inferred above which:



          ${2^{4}} = 16$



          possible splits.



          An algorithm in python 3.5 to solve this problem



          import itertools

          def getSplits(myciphers):
          comb=
          for split in [p for p in itertools.product([0,1], repeat=4)]:
          tsplit=
          tsplit.append(myciphers[0])
          for c,s in zip(myciphers[1:],split):
          if s == 1:
          tsplit.append("-")
          tsplit.append(c)

          comb.append("".join(tsplit))
          return comb

          # Test Case 1
          myciphers="12345"
          print(getSplits(myciphers))

          # Test Case 2
          myciphers="ABCD"
          print(getSplits(myciphers))


          The output of this program is as follows:



          rcolomina@workstation-rig:~$ python boo.py
          ['12345', '1234-5', '123-45', '123-4-5', '12-345', '12-34-5', '12-3-45', '12-3-4-5', '1-2345', '1-234-5', '1-23-45', '1-23-4-5', '1-2-345', '1-2-34-5', '1-2-3-45', '1-2-3-4-5']
          ['ABCD', 'ABCD', 'ABC-D', 'ABC-D', 'AB-CD', 'AB-CD', 'AB-C-D', 'AB-C-D', 'A-BCD', 'A-BCD', 'A-BC-D', 'A-BC-D', 'A-B-CD', 'A-B-CD', 'A-B-C-D', 'A-B-C-D']





          share|cite|improve this answer









          $endgroup$





















            3












            $begingroup$

            When you have a sequence of $n$ numbers, you can $n-1$ slots to make cuts. So we need to know all the ways we can choose $0$ cuts out if it, then $1$ cut, $2$ cuts, etc



            The total number of ways to choose the cuts is $$sum_{k=0}^{n-1} { {n-1}choose{k}} =2^{n-1} $$



            To prove this equality, use a subtle trick: Set $2^{n-1} = (1+1)^{n-1}$ and use the Binomial Theorem.






            share|cite|improve this answer









            $endgroup$





















              2












              $begingroup$

              Look at the cuts as a binary number where each digit i of the number indicates if we cut between digit i and i+1 in the real number.

              for example:

              12345 would be 0000.

              12-345 would be 0100.



              Now,for a number of size n our binary number would be of size n-1,how many unique values can a n-1 digits binary number represent?
              $$2^{(n-1)}$$.






              share|cite|improve this answer









              $endgroup$













                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: "69"
                };
                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',
                autoActivateHeartbeat: false,
                convertImagesToLinks: true,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: 10,
                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
                },
                noCode: true, onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                });


                }
                });














                draft saved

                draft discarded


















                StackExchange.ready(
                function () {
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3031327%2fall-possible-ways-to-split-a-number%23new-answer', 'question_page');
                }
                );

                Post as a guest















                Required, but never shown

























                3 Answers
                3






                active

                oldest

                votes








                3 Answers
                3






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                1












                $begingroup$

                Your problem can be solved using permutation with repetition in general.



                Permutations with repetition



                Ordered arrangements of the elements of a set S of length n where repetition is allowed are called n-tuples, but have sometimes been referred to as permutations with repetition although they are not permutations in general. They are also called words over the alphabet S in some contexts. If the set S has k elements, the number of n-tuples over S is:



                The general formula is $ k^n $ where $k$ is the number of elements of S and $n$ the length of the tuple to form.



                There is no restriction on how often an element can appear in an n-tuple, but if restrictions are placed on how often an element can appear, this formula is no longer valid.



                In particular your problem to split 5 figures is equivalent to arrange 4 elements ($n=4$) from a set S of 2 elements ($k=2$) i.e.



                ${"-", "Nothing"}$



                in order to get 4 tuples;



                $("-/Nothing","-/Nothing","-/Nothing","-/Nothing")$ where slash $/$ means logical operator "or".



                Therefore you will get the amount that you have inferred above which:



                ${2^{4}} = 16$



                possible splits.



                An algorithm in python 3.5 to solve this problem



                import itertools

                def getSplits(myciphers):
                comb=
                for split in [p for p in itertools.product([0,1], repeat=4)]:
                tsplit=
                tsplit.append(myciphers[0])
                for c,s in zip(myciphers[1:],split):
                if s == 1:
                tsplit.append("-")
                tsplit.append(c)

                comb.append("".join(tsplit))
                return comb

                # Test Case 1
                myciphers="12345"
                print(getSplits(myciphers))

                # Test Case 2
                myciphers="ABCD"
                print(getSplits(myciphers))


                The output of this program is as follows:



                rcolomina@workstation-rig:~$ python boo.py
                ['12345', '1234-5', '123-45', '123-4-5', '12-345', '12-34-5', '12-3-45', '12-3-4-5', '1-2345', '1-234-5', '1-23-45', '1-23-4-5', '1-2-345', '1-2-34-5', '1-2-3-45', '1-2-3-4-5']
                ['ABCD', 'ABCD', 'ABC-D', 'ABC-D', 'AB-CD', 'AB-CD', 'AB-C-D', 'AB-C-D', 'A-BCD', 'A-BCD', 'A-BC-D', 'A-BC-D', 'A-B-CD', 'A-B-CD', 'A-B-C-D', 'A-B-C-D']





                share|cite|improve this answer









                $endgroup$


















                  1












                  $begingroup$

                  Your problem can be solved using permutation with repetition in general.



                  Permutations with repetition



                  Ordered arrangements of the elements of a set S of length n where repetition is allowed are called n-tuples, but have sometimes been referred to as permutations with repetition although they are not permutations in general. They are also called words over the alphabet S in some contexts. If the set S has k elements, the number of n-tuples over S is:



                  The general formula is $ k^n $ where $k$ is the number of elements of S and $n$ the length of the tuple to form.



                  There is no restriction on how often an element can appear in an n-tuple, but if restrictions are placed on how often an element can appear, this formula is no longer valid.



                  In particular your problem to split 5 figures is equivalent to arrange 4 elements ($n=4$) from a set S of 2 elements ($k=2$) i.e.



                  ${"-", "Nothing"}$



                  in order to get 4 tuples;



                  $("-/Nothing","-/Nothing","-/Nothing","-/Nothing")$ where slash $/$ means logical operator "or".



                  Therefore you will get the amount that you have inferred above which:



                  ${2^{4}} = 16$



                  possible splits.



                  An algorithm in python 3.5 to solve this problem



                  import itertools

                  def getSplits(myciphers):
                  comb=
                  for split in [p for p in itertools.product([0,1], repeat=4)]:
                  tsplit=
                  tsplit.append(myciphers[0])
                  for c,s in zip(myciphers[1:],split):
                  if s == 1:
                  tsplit.append("-")
                  tsplit.append(c)

                  comb.append("".join(tsplit))
                  return comb

                  # Test Case 1
                  myciphers="12345"
                  print(getSplits(myciphers))

                  # Test Case 2
                  myciphers="ABCD"
                  print(getSplits(myciphers))


                  The output of this program is as follows:



                  rcolomina@workstation-rig:~$ python boo.py
                  ['12345', '1234-5', '123-45', '123-4-5', '12-345', '12-34-5', '12-3-45', '12-3-4-5', '1-2345', '1-234-5', '1-23-45', '1-23-4-5', '1-2-345', '1-2-34-5', '1-2-3-45', '1-2-3-4-5']
                  ['ABCD', 'ABCD', 'ABC-D', 'ABC-D', 'AB-CD', 'AB-CD', 'AB-C-D', 'AB-C-D', 'A-BCD', 'A-BCD', 'A-BC-D', 'A-BC-D', 'A-B-CD', 'A-B-CD', 'A-B-C-D', 'A-B-C-D']





                  share|cite|improve this answer









                  $endgroup$
















                    1












                    1








                    1





                    $begingroup$

                    Your problem can be solved using permutation with repetition in general.



                    Permutations with repetition



                    Ordered arrangements of the elements of a set S of length n where repetition is allowed are called n-tuples, but have sometimes been referred to as permutations with repetition although they are not permutations in general. They are also called words over the alphabet S in some contexts. If the set S has k elements, the number of n-tuples over S is:



                    The general formula is $ k^n $ where $k$ is the number of elements of S and $n$ the length of the tuple to form.



                    There is no restriction on how often an element can appear in an n-tuple, but if restrictions are placed on how often an element can appear, this formula is no longer valid.



                    In particular your problem to split 5 figures is equivalent to arrange 4 elements ($n=4$) from a set S of 2 elements ($k=2$) i.e.



                    ${"-", "Nothing"}$



                    in order to get 4 tuples;



                    $("-/Nothing","-/Nothing","-/Nothing","-/Nothing")$ where slash $/$ means logical operator "or".



                    Therefore you will get the amount that you have inferred above which:



                    ${2^{4}} = 16$



                    possible splits.



                    An algorithm in python 3.5 to solve this problem



                    import itertools

                    def getSplits(myciphers):
                    comb=
                    for split in [p for p in itertools.product([0,1], repeat=4)]:
                    tsplit=
                    tsplit.append(myciphers[0])
                    for c,s in zip(myciphers[1:],split):
                    if s == 1:
                    tsplit.append("-")
                    tsplit.append(c)

                    comb.append("".join(tsplit))
                    return comb

                    # Test Case 1
                    myciphers="12345"
                    print(getSplits(myciphers))

                    # Test Case 2
                    myciphers="ABCD"
                    print(getSplits(myciphers))


                    The output of this program is as follows:



                    rcolomina@workstation-rig:~$ python boo.py
                    ['12345', '1234-5', '123-45', '123-4-5', '12-345', '12-34-5', '12-3-45', '12-3-4-5', '1-2345', '1-234-5', '1-23-45', '1-23-4-5', '1-2-345', '1-2-34-5', '1-2-3-45', '1-2-3-4-5']
                    ['ABCD', 'ABCD', 'ABC-D', 'ABC-D', 'AB-CD', 'AB-CD', 'AB-C-D', 'AB-C-D', 'A-BCD', 'A-BCD', 'A-BC-D', 'A-BC-D', 'A-B-CD', 'A-B-CD', 'A-B-C-D', 'A-B-C-D']





                    share|cite|improve this answer









                    $endgroup$



                    Your problem can be solved using permutation with repetition in general.



                    Permutations with repetition



                    Ordered arrangements of the elements of a set S of length n where repetition is allowed are called n-tuples, but have sometimes been referred to as permutations with repetition although they are not permutations in general. They are also called words over the alphabet S in some contexts. If the set S has k elements, the number of n-tuples over S is:



                    The general formula is $ k^n $ where $k$ is the number of elements of S and $n$ the length of the tuple to form.



                    There is no restriction on how often an element can appear in an n-tuple, but if restrictions are placed on how often an element can appear, this formula is no longer valid.



                    In particular your problem to split 5 figures is equivalent to arrange 4 elements ($n=4$) from a set S of 2 elements ($k=2$) i.e.



                    ${"-", "Nothing"}$



                    in order to get 4 tuples;



                    $("-/Nothing","-/Nothing","-/Nothing","-/Nothing")$ where slash $/$ means logical operator "or".



                    Therefore you will get the amount that you have inferred above which:



                    ${2^{4}} = 16$



                    possible splits.



                    An algorithm in python 3.5 to solve this problem



                    import itertools

                    def getSplits(myciphers):
                    comb=
                    for split in [p for p in itertools.product([0,1], repeat=4)]:
                    tsplit=
                    tsplit.append(myciphers[0])
                    for c,s in zip(myciphers[1:],split):
                    if s == 1:
                    tsplit.append("-")
                    tsplit.append(c)

                    comb.append("".join(tsplit))
                    return comb

                    # Test Case 1
                    myciphers="12345"
                    print(getSplits(myciphers))

                    # Test Case 2
                    myciphers="ABCD"
                    print(getSplits(myciphers))


                    The output of this program is as follows:



                    rcolomina@workstation-rig:~$ python boo.py
                    ['12345', '1234-5', '123-45', '123-4-5', '12-345', '12-34-5', '12-3-45', '12-3-4-5', '1-2345', '1-234-5', '1-23-45', '1-23-4-5', '1-2-345', '1-2-34-5', '1-2-3-45', '1-2-3-4-5']
                    ['ABCD', 'ABCD', 'ABC-D', 'ABC-D', 'AB-CD', 'AB-CD', 'AB-C-D', 'AB-C-D', 'A-BCD', 'A-BCD', 'A-BC-D', 'A-BC-D', 'A-B-CD', 'A-B-CD', 'A-B-C-D', 'A-B-C-D']






                    share|cite|improve this answer












                    share|cite|improve this answer



                    share|cite|improve this answer










                    answered Dec 8 '18 at 17:32









                    Rubén ColominaRubén Colomina

                    436




                    436























                        3












                        $begingroup$

                        When you have a sequence of $n$ numbers, you can $n-1$ slots to make cuts. So we need to know all the ways we can choose $0$ cuts out if it, then $1$ cut, $2$ cuts, etc



                        The total number of ways to choose the cuts is $$sum_{k=0}^{n-1} { {n-1}choose{k}} =2^{n-1} $$



                        To prove this equality, use a subtle trick: Set $2^{n-1} = (1+1)^{n-1}$ and use the Binomial Theorem.






                        share|cite|improve this answer









                        $endgroup$


















                          3












                          $begingroup$

                          When you have a sequence of $n$ numbers, you can $n-1$ slots to make cuts. So we need to know all the ways we can choose $0$ cuts out if it, then $1$ cut, $2$ cuts, etc



                          The total number of ways to choose the cuts is $$sum_{k=0}^{n-1} { {n-1}choose{k}} =2^{n-1} $$



                          To prove this equality, use a subtle trick: Set $2^{n-1} = (1+1)^{n-1}$ and use the Binomial Theorem.






                          share|cite|improve this answer









                          $endgroup$
















                            3












                            3








                            3





                            $begingroup$

                            When you have a sequence of $n$ numbers, you can $n-1$ slots to make cuts. So we need to know all the ways we can choose $0$ cuts out if it, then $1$ cut, $2$ cuts, etc



                            The total number of ways to choose the cuts is $$sum_{k=0}^{n-1} { {n-1}choose{k}} =2^{n-1} $$



                            To prove this equality, use a subtle trick: Set $2^{n-1} = (1+1)^{n-1}$ and use the Binomial Theorem.






                            share|cite|improve this answer









                            $endgroup$



                            When you have a sequence of $n$ numbers, you can $n-1$ slots to make cuts. So we need to know all the ways we can choose $0$ cuts out if it, then $1$ cut, $2$ cuts, etc



                            The total number of ways to choose the cuts is $$sum_{k=0}^{n-1} { {n-1}choose{k}} =2^{n-1} $$



                            To prove this equality, use a subtle trick: Set $2^{n-1} = (1+1)^{n-1}$ and use the Binomial Theorem.







                            share|cite|improve this answer












                            share|cite|improve this answer



                            share|cite|improve this answer










                            answered Dec 8 '18 at 17:05









                            WaveXWaveX

                            2,6522722




                            2,6522722























                                2












                                $begingroup$

                                Look at the cuts as a binary number where each digit i of the number indicates if we cut between digit i and i+1 in the real number.

                                for example:

                                12345 would be 0000.

                                12-345 would be 0100.



                                Now,for a number of size n our binary number would be of size n-1,how many unique values can a n-1 digits binary number represent?
                                $$2^{(n-1)}$$.






                                share|cite|improve this answer









                                $endgroup$


















                                  2












                                  $begingroup$

                                  Look at the cuts as a binary number where each digit i of the number indicates if we cut between digit i and i+1 in the real number.

                                  for example:

                                  12345 would be 0000.

                                  12-345 would be 0100.



                                  Now,for a number of size n our binary number would be of size n-1,how many unique values can a n-1 digits binary number represent?
                                  $$2^{(n-1)}$$.






                                  share|cite|improve this answer









                                  $endgroup$
















                                    2












                                    2








                                    2





                                    $begingroup$

                                    Look at the cuts as a binary number where each digit i of the number indicates if we cut between digit i and i+1 in the real number.

                                    for example:

                                    12345 would be 0000.

                                    12-345 would be 0100.



                                    Now,for a number of size n our binary number would be of size n-1,how many unique values can a n-1 digits binary number represent?
                                    $$2^{(n-1)}$$.






                                    share|cite|improve this answer









                                    $endgroup$



                                    Look at the cuts as a binary number where each digit i of the number indicates if we cut between digit i and i+1 in the real number.

                                    for example:

                                    12345 would be 0000.

                                    12-345 would be 0100.



                                    Now,for a number of size n our binary number would be of size n-1,how many unique values can a n-1 digits binary number represent?
                                    $$2^{(n-1)}$$.







                                    share|cite|improve this answer












                                    share|cite|improve this answer



                                    share|cite|improve this answer










                                    answered Dec 8 '18 at 17:03









                                    AdddisonAdddison

                                    846




                                    846






























                                        draft saved

                                        draft discarded




















































                                        Thanks for contributing an answer to Mathematics Stack Exchange!


                                        • Please be sure to answer the question. Provide details and share your research!

                                        But avoid



                                        • Asking for help, clarification, or responding to other answers.

                                        • Making statements based on opinion; back them up with references or personal experience.


                                        Use MathJax to format equations. MathJax reference.


                                        To learn more, see our tips on writing great answers.




                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function () {
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3031327%2fall-possible-ways-to-split-a-number%23new-answer', 'question_page');
                                        }
                                        );

                                        Post as a guest















                                        Required, but never shown





















































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown

































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown







                                        Popular posts from this blog

                                        Plaza Victoria

                                        In PowerPoint, is there a keyboard shortcut for bulleted / numbered list?

                                        How to put 3 figures in Latex with 2 figures side by side and 1 below these side by side images but in...