How to convert list of digits to number? [closed]












4














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















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


















    4














    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















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
















      4












      4








      4







      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















      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















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 8 at 9:46









      Henrik Schumacher

      48.6k467137




      48.6k467137










      asked Dec 8 at 5:04









      user61054

      334




      334




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




      closed 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


















          5














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

          (* 1243 *)





          share|improve this answer































            4














            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





















            2














            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





























              2














              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



















              2














              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









                5














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

                (* 1243 *)





                share|improve this answer




























                  5














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

                  (* 1243 *)





                  share|improve this answer


























                    5












                    5








                    5






                    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









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

                    4,0441928




                    4,0441928










                    answered Dec 8 at 5:10









                    Mike Honeychurch

                    30.9k268143




                    30.9k268143























                        4














                        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


















                        4














                        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
















                        4












                        4








                        4






                        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









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

                        4,0441928




                        4,0441928












                        • 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













                        2














                        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


























                          2














                          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
























                            2












                            2








                            2






                            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























                                2














                                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
















                                2














                                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














                                2












                                2








                                2






                                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,4931115




                                1,4931115












                                • 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











                                2














                                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




























                                  2














                                  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


























                                    2












                                    2








                                    2






                                    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

                                    48.6k467137




                                    48.6k467137















                                        Popular posts from this blog

                                        How to change which sound is reproduced for terminal bell?

                                        Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

                                        Can I use Tabulator js library in my java Spring + Thymeleaf project?