How to convert list of digits to number? [on hold]











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











put on hold as off-topic by corey979, Daniel Lichtblau, AccidentalFourierTransform, Michael E2, eyorble Dec 8 at 17:04


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – corey979, Daniel Lichtblau, AccidentalFourierTransform, Michael E2, eyorble

If this question can be reworded to fit the rules in the help center, please edit the question.

















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











    put on hold as off-topic by corey979, Daniel Lichtblau, AccidentalFourierTransform, Michael E2, eyorble Dec 8 at 17:04


    This question appears to be off-topic. The users who voted to close gave this specific reason:


    • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – corey979, Daniel Lichtblau, AccidentalFourierTransform, Michael E2, eyorble

    If this question can be reworded to fit the rules in the help center, please edit the question.















      up vote
      4
      down vote

      favorite









      up vote
      4
      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 Dec 8 at 9:46









      Henrik Schumacher

      47.2k466134




      47.2k466134






      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 Dec 8 at 5:04









      user61054

      332




      332




      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.




      put on hold as off-topic by corey979, Daniel Lichtblau, AccidentalFourierTransform, Michael E2, eyorble Dec 8 at 17:04


      This question appears to be off-topic. The users who voted to close gave this specific reason:


      • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – corey979, Daniel Lichtblau, AccidentalFourierTransform, Michael E2, eyorble

      If this question can be reworded to fit the rules in the help center, please edit the question.




      put on hold as off-topic by corey979, Daniel Lichtblau, AccidentalFourierTransform, Michael E2, eyorble Dec 8 at 17:04


      This question appears to be off-topic. The users who voted to close gave this specific reason:


      • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – corey979, Daniel Lichtblau, AccidentalFourierTransform, Michael E2, eyorble

      If this question can be reworded to fit the rules in the help center, please edit the question.






















          5 Answers
          5






          active

          oldest

          votes

















          up vote
          5
          down vote













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

          (* 1243 *)





          share|improve this answer






























            up vote
            4
            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
              Dec 8 at 6:40










            • @user61054 Do you want to know what the figurative meaning of "wheel" or how the function Fold works?
              – Αλέξανδρος Ζεγγ
              Dec 8 at 11:28




















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





















              • Are you really serious that you would not recommend this? :)
                – Buddha_the_Scientist
                Dec 8 at 12:15


















              up vote
              2
              down vote













              Here is a 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|improve this answer






























                5 Answers
                5






                active

                oldest

                votes








                5 Answers
                5






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes








                up vote
                5
                down vote













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

                (* 1243 *)





                share|improve this answer



























                  up vote
                  5
                  down vote













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

                  (* 1243 *)





                  share|improve this answer

























                    up vote
                    5
                    down vote










                    up vote
                    5
                    down vote









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

                    (* 1243 *)





                    share|improve this answer














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

                    (* 1243 *)






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Dec 8 at 11:49









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

                    3,8021927




                    3,8021927










                    answered Dec 8 at 5:10









                    Mike Honeychurch

                    30.9k268143




                    30.9k268143






















                        up vote
                        4
                        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
                          Dec 8 at 6:40










                        • @user61054 Do you want to know what the figurative meaning of "wheel" or how the function Fold works?
                          – Αλέξανδρος Ζεγγ
                          Dec 8 at 11:28

















                        up vote
                        4
                        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
                          Dec 8 at 6:40










                        • @user61054 Do you want to know what the figurative meaning of "wheel" or how the function Fold works?
                          – Αλέξανδρος Ζεγγ
                          Dec 8 at 11:28















                        up vote
                        4
                        down vote










                        up vote
                        4
                        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 Dec 8 at 5:28









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

                        3,8021927




                        3,8021927












                        • 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
                          Dec 8 at 6:40










                        • @user61054 Do you want to know what the figurative meaning of "wheel" or how the function Fold works?
                          – Αλέξανδρος Ζεγγ
                          Dec 8 at 11:28




















                        • 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
                          Dec 8 at 6:40










                        • @user61054 Do you want to know what the figurative meaning of "wheel" or how the function Fold works?
                          – Αλέξανδρος Ζεγγ
                          Dec 8 at 11:28


















                        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
                        Dec 8 at 6:40




                        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
                        Dec 8 at 6:40












                        @user61054 Do you want to know what the figurative meaning of "wheel" or how the function Fold works?
                        – Αλέξανδρος Ζεγγ
                        Dec 8 at 11:28






                        @user61054 Do you want to know what the figurative meaning of "wheel" or how the function Fold works?
                        – Αλέξανδρος Ζεγγ
                        Dec 8 at 11:28












                        up vote
                        2
                        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
                          2
                          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
                            2
                            down vote










                            up vote
                            2
                            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 Dec 8 at 6:18









                            Nasser

                            57.2k486205




                            57.2k486205






















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





















                                • Are you really serious that you would not recommend this? :)
                                  – Buddha_the_Scientist
                                  Dec 8 at 12:15















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





















                                • Are you really serious that you would not recommend this? :)
                                  – Buddha_the_Scientist
                                  Dec 8 at 12:15













                                up vote
                                2
                                down vote










                                up vote
                                2
                                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 Dec 8 at 6:30









                                Shredderroy

                                1,4631115




                                1,4631115












                                • Are you really serious that you would not recommend this? :)
                                  – Buddha_the_Scientist
                                  Dec 8 at 12:15


















                                • Are you really serious that you would not recommend this? :)
                                  – Buddha_the_Scientist
                                  Dec 8 at 12:15
















                                Are you really serious that you would not recommend this? :)
                                – Buddha_the_Scientist
                                Dec 8 at 12:15




                                Are you really serious that you would not recommend this? :)
                                – Buddha_the_Scientist
                                Dec 8 at 12:15










                                up vote
                                2
                                down vote













                                Here is a 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|improve this answer



























                                  up vote
                                  2
                                  down vote













                                  Here is a 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|improve this answer

























                                    up vote
                                    2
                                    down vote










                                    up vote
                                    2
                                    down vote









                                    Here is a 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|improve this answer














                                    Here is a 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|improve this answer














                                    share|improve this answer



                                    share|improve this answer








                                    edited Dec 8 at 9:52









                                    corey979

                                    20.7k64282




                                    20.7k64282










                                    answered Dec 8 at 6:57









                                    Henrik Schumacher

                                    47.2k466134




                                    47.2k466134















                                        Popular posts from this blog

                                        Morgemoulin

                                        Scott Moir

                                        Souastre