How to take list to number?











up vote
2
down vote

favorite












I have a list such as:



a = {1, 2, 4, 3};


and I want to get the 'number' of the list. For this example, I want to get this number: 1243. I do not know how to get it easily. For now, my solution is:
a[[1]]*10^3+a[[2]]*10^2+a[[3]]*10^1+a[[4]];
It works. But it is too complex. I want to know a way more convenient.










share|improve this question









New contributor




user61054 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
























    up vote
    2
    down vote

    favorite












    I have a list such as:



    a = {1, 2, 4, 3};


    and I want to get the 'number' of the list. For this example, I want to get this number: 1243. I do not know how to get it easily. For now, my solution is:
    a[[1]]*10^3+a[[2]]*10^2+a[[3]]*10^1+a[[4]];
    It works. But it is too complex. I want to know a way more convenient.










    share|improve this question









    New contributor




    user61054 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






















      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      I have a list such as:



      a = {1, 2, 4, 3};


      and I want to get the 'number' of the list. For this example, I want to get this number: 1243. I do not know how to get it easily. For now, my solution is:
      a[[1]]*10^3+a[[2]]*10^2+a[[3]]*10^1+a[[4]];
      It works. But it is too complex. I want to know a way more convenient.










      share|improve this question









      New contributor




      user61054 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I have a list such as:



      a = {1, 2, 4, 3};


      and I want to get the 'number' of the list. For this example, I want to get this number: 1243. I do not know how to get it easily. For now, my solution is:
      a[[1]]*10^3+a[[2]]*10^2+a[[3]]*10^1+a[[4]];
      It works. But it is too complex. I want to know a way more convenient.







      functions special-functions






      share|improve this question









      New contributor




      user61054 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      user61054 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited 1 hour ago









      Αλέξανδρος Ζεγγ

      3,6531927




      3,6531927






      New contributor




      user61054 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 1 hour ago









      user61054

      211




      211




      New contributor




      user61054 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      user61054 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      user61054 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          5 Answers
          5






          active

          oldest

          votes

















          up vote
          3
          down vote













          a={1,2,4,3};
          FromDigits[a]

          (* 1234 *)





          share|improve this answer




























            up vote
            2
            down vote













            Other than the built-in FromDigits, we can build our wheel



            Fold[{10, 1}.{##} &, a]





            share|improve this answer





















            • I want to know what is the mean of 'wheel'. Is it a function to achieve something? I know what you express, but I am interest in the meaning of 'wheel'.
              – user61054
              24 mins ago


















            up vote
            0
            down vote













            Best way would be to use build-in function FromDigits as shown above.



            But just in case you'd like a convoluted way to do it, here is another option



            a = {1, 2, 4, 3};
            ToExpression[StringJoin[ToString[#] & /@ a]]


            Mathematica graphics






            share|improve this answer




























              up vote
              0
              down vote













              These are some methods I would not recommend:



              lst = {1, 2, 3, 4};

              f = (Curry[StringRiffle][""] /* ToExpression);

              g = (Through[{
              Identity,
              Length /* Range /* Reverse /* Curry[Plus][-1] /* Curry[Power, 2][10]
              }[#]] & /* MapThread[Times] /* Total);

              f[lst] (* 1234 *)
              g[lst] (* 1234 *)





              share|improve this answer




























                up vote
                0
                down vote













                Here is method that is faster than `FromDigits for the construction of many numbers at once:



                a = RandomInteger[{1, 9}, {1000000, 10}];
                r1 = FromDigits /@ a; // RepeatedTiming // First
                r2 = FromDigits[Transpose[a]]; // RepeatedTiming
                r3 = a.(10^Range[9, 0, -1]); // RepeatedTiming // First
                r1 == r2 == r3



                0.466



                0.068



                0.040



                True




                Admittedly, FromDigits[Transpose[a]] is only slower than a.(10^Range[9, 0, -1]) because of Transpose.





                share





















                  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
                  });


                  }
                  });






                  user61054 is a new contributor. Be nice, and check out our Code of Conduct.










                  draft saved

                  draft discarded


















                  StackExchange.ready(
                  function () {
                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f187524%2fhow-to-take-list-to-number%23new-answer', 'question_page');
                  }
                  );

                  Post as a guest















                  Required, but never shown

























                  5 Answers
                  5






                  active

                  oldest

                  votes








                  5 Answers
                  5






                  active

                  oldest

                  votes









                  active

                  oldest

                  votes






                  active

                  oldest

                  votes








                  up vote
                  3
                  down vote













                  a={1,2,4,3};
                  FromDigits[a]

                  (* 1234 *)





                  share|improve this answer

























                    up vote
                    3
                    down vote













                    a={1,2,4,3};
                    FromDigits[a]

                    (* 1234 *)





                    share|improve this answer























                      up vote
                      3
                      down vote










                      up vote
                      3
                      down vote









                      a={1,2,4,3};
                      FromDigits[a]

                      (* 1234 *)





                      share|improve this answer












                      a={1,2,4,3};
                      FromDigits[a]

                      (* 1234 *)






                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered 1 hour ago









                      Mike Honeychurch

                      30.8k268143




                      30.8k268143






















                          up vote
                          2
                          down vote













                          Other than the built-in FromDigits, we can build our wheel



                          Fold[{10, 1}.{##} &, a]





                          share|improve this answer





















                          • I want to know what is the mean of 'wheel'. Is it a function to achieve something? I know what you express, but I am interest in the meaning of 'wheel'.
                            – user61054
                            24 mins ago















                          up vote
                          2
                          down vote













                          Other than the built-in FromDigits, we can build our wheel



                          Fold[{10, 1}.{##} &, a]





                          share|improve this answer





















                          • I want to know what is the mean of 'wheel'. Is it a function to achieve something? I know what you express, but I am interest in the meaning of 'wheel'.
                            – user61054
                            24 mins ago













                          up vote
                          2
                          down vote










                          up vote
                          2
                          down vote









                          Other than the built-in FromDigits, we can build our wheel



                          Fold[{10, 1}.{##} &, a]





                          share|improve this answer












                          Other than the built-in FromDigits, we can build our wheel



                          Fold[{10, 1}.{##} &, a]






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered 1 hour ago









                          Αλέξανδρος Ζεγγ

                          3,6531927




                          3,6531927












                          • I want to know what is the mean of 'wheel'. Is it a function to achieve something? I know what you express, but I am interest in the meaning of 'wheel'.
                            – user61054
                            24 mins ago


















                          • I want to know what is the mean of 'wheel'. Is it a function to achieve something? I know what you express, but I am interest in the meaning of 'wheel'.
                            – user61054
                            24 mins ago
















                          I want to know what is the mean of 'wheel'. Is it a function to achieve something? I know what you express, but I am interest in the meaning of 'wheel'.
                          – user61054
                          24 mins ago




                          I want to know what is the mean of 'wheel'. Is it a function to achieve something? I know what you express, but I am interest in the meaning of 'wheel'.
                          – user61054
                          24 mins ago










                          up vote
                          0
                          down vote













                          Best way would be to use build-in function FromDigits as shown above.



                          But just in case you'd like a convoluted way to do it, here is another option



                          a = {1, 2, 4, 3};
                          ToExpression[StringJoin[ToString[#] & /@ a]]


                          Mathematica graphics






                          share|improve this answer

























                            up vote
                            0
                            down vote













                            Best way would be to use build-in function FromDigits as shown above.



                            But just in case you'd like a convoluted way to do it, here is another option



                            a = {1, 2, 4, 3};
                            ToExpression[StringJoin[ToString[#] & /@ a]]


                            Mathematica graphics






                            share|improve this answer























                              up vote
                              0
                              down vote










                              up vote
                              0
                              down vote









                              Best way would be to use build-in function FromDigits as shown above.



                              But just in case you'd like a convoluted way to do it, here is another option



                              a = {1, 2, 4, 3};
                              ToExpression[StringJoin[ToString[#] & /@ a]]


                              Mathematica graphics






                              share|improve this answer












                              Best way would be to use build-in function FromDigits as shown above.



                              But just in case you'd like a convoluted way to do it, here is another option



                              a = {1, 2, 4, 3};
                              ToExpression[StringJoin[ToString[#] & /@ a]]


                              Mathematica graphics







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered 46 mins ago









                              Nasser

                              57.1k486205




                              57.1k486205






















                                  up vote
                                  0
                                  down vote













                                  These are some methods I would not recommend:



                                  lst = {1, 2, 3, 4};

                                  f = (Curry[StringRiffle][""] /* ToExpression);

                                  g = (Through[{
                                  Identity,
                                  Length /* Range /* Reverse /* Curry[Plus][-1] /* Curry[Power, 2][10]
                                  }[#]] & /* MapThread[Times] /* Total);

                                  f[lst] (* 1234 *)
                                  g[lst] (* 1234 *)





                                  share|improve this answer

























                                    up vote
                                    0
                                    down vote













                                    These are some methods I would not recommend:



                                    lst = {1, 2, 3, 4};

                                    f = (Curry[StringRiffle][""] /* ToExpression);

                                    g = (Through[{
                                    Identity,
                                    Length /* Range /* Reverse /* Curry[Plus][-1] /* Curry[Power, 2][10]
                                    }[#]] & /* MapThread[Times] /* Total);

                                    f[lst] (* 1234 *)
                                    g[lst] (* 1234 *)





                                    share|improve this answer























                                      up vote
                                      0
                                      down vote










                                      up vote
                                      0
                                      down vote









                                      These are some methods I would not recommend:



                                      lst = {1, 2, 3, 4};

                                      f = (Curry[StringRiffle][""] /* ToExpression);

                                      g = (Through[{
                                      Identity,
                                      Length /* Range /* Reverse /* Curry[Plus][-1] /* Curry[Power, 2][10]
                                      }[#]] & /* MapThread[Times] /* Total);

                                      f[lst] (* 1234 *)
                                      g[lst] (* 1234 *)





                                      share|improve this answer












                                      These are some methods I would not recommend:



                                      lst = {1, 2, 3, 4};

                                      f = (Curry[StringRiffle][""] /* ToExpression);

                                      g = (Through[{
                                      Identity,
                                      Length /* Range /* Reverse /* Curry[Plus][-1] /* Curry[Power, 2][10]
                                      }[#]] & /* MapThread[Times] /* Total);

                                      f[lst] (* 1234 *)
                                      g[lst] (* 1234 *)






                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered 34 mins ago









                                      Shredderroy

                                      1,4181115




                                      1,4181115






















                                          up vote
                                          0
                                          down vote













                                          Here is method that is faster than `FromDigits for the construction of many numbers at once:



                                          a = RandomInteger[{1, 9}, {1000000, 10}];
                                          r1 = FromDigits /@ a; // RepeatedTiming // First
                                          r2 = FromDigits[Transpose[a]]; // RepeatedTiming
                                          r3 = a.(10^Range[9, 0, -1]); // RepeatedTiming // First
                                          r1 == r2 == r3



                                          0.466



                                          0.068



                                          0.040



                                          True




                                          Admittedly, FromDigits[Transpose[a]] is only slower than a.(10^Range[9, 0, -1]) because of Transpose.





                                          share

























                                            up vote
                                            0
                                            down vote













                                            Here is method that is faster than `FromDigits for the construction of many numbers at once:



                                            a = RandomInteger[{1, 9}, {1000000, 10}];
                                            r1 = FromDigits /@ a; // RepeatedTiming // First
                                            r2 = FromDigits[Transpose[a]]; // RepeatedTiming
                                            r3 = a.(10^Range[9, 0, -1]); // RepeatedTiming // First
                                            r1 == r2 == r3



                                            0.466



                                            0.068



                                            0.040



                                            True




                                            Admittedly, FromDigits[Transpose[a]] is only slower than a.(10^Range[9, 0, -1]) because of Transpose.





                                            share























                                              up vote
                                              0
                                              down vote










                                              up vote
                                              0
                                              down vote









                                              Here is method that is faster than `FromDigits for the construction of many numbers at once:



                                              a = RandomInteger[{1, 9}, {1000000, 10}];
                                              r1 = FromDigits /@ a; // RepeatedTiming // First
                                              r2 = FromDigits[Transpose[a]]; // RepeatedTiming
                                              r3 = a.(10^Range[9, 0, -1]); // RepeatedTiming // First
                                              r1 == r2 == r3



                                              0.466



                                              0.068



                                              0.040



                                              True




                                              Admittedly, FromDigits[Transpose[a]] is only slower than a.(10^Range[9, 0, -1]) because of Transpose.





                                              share












                                              Here is method that is faster than `FromDigits for the construction of many numbers at once:



                                              a = RandomInteger[{1, 9}, {1000000, 10}];
                                              r1 = FromDigits /@ a; // RepeatedTiming // First
                                              r2 = FromDigits[Transpose[a]]; // RepeatedTiming
                                              r3 = a.(10^Range[9, 0, -1]); // RepeatedTiming // First
                                              r1 == r2 == r3



                                              0.466



                                              0.068



                                              0.040



                                              True




                                              Admittedly, FromDigits[Transpose[a]] is only slower than a.(10^Range[9, 0, -1]) because of Transpose.






                                              share











                                              share


                                              share










                                              answered 6 mins ago









                                              Henrik Schumacher

                                              46.6k466133




                                              46.6k466133






















                                                  user61054 is a new contributor. Be nice, and check out our Code of Conduct.










                                                  draft saved

                                                  draft discarded


















                                                  user61054 is a new contributor. Be nice, and check out our Code of Conduct.













                                                  user61054 is a new contributor. Be nice, and check out our Code of Conduct.












                                                  user61054 is a new contributor. Be nice, and check out our Code of Conduct.
















                                                  Thanks for contributing an answer to Mathematica 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.





                                                  Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                                  Please pay close attention to the following guidance:


                                                  • 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.


                                                  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%2fmathematica.stackexchange.com%2fquestions%2f187524%2fhow-to-take-list-to-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

                                                  Create new schema in PostgreSQL using DBeaver

                                                  Deepest pit of an array with Javascript: test on Codility

                                                  Costa Masnaga