Search code examples
wolfram-mathematicamathematica-7

Concatenate two integers in Mathematica 7


What is the most efficient way to concatenate two positive integers in Mathematica 7?

cc[123, 4567] >> 1234567

What about more than two?

cc[123, 4, 567, 89] >> 123456789


Solution

  • This will be slightly faster for many integers, than your last solution:

    ToExpression[StringJoin @@ Map[IntegerString, {##}]] &
    

    A more concise alternative is to accept a single argument, assuming it to be a list, rather than a sequence, of numbers to concatenate:

    ToExpression@StringJoin@IntegerString@#&
    

    which is based on IntegerString being Listable.