Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 883
Mr.Wizard Avatar asked Feb 03 '23 18:02

Mr.Wizard


1 Answers

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.

like image 175
Leonid Shifrin Avatar answered Feb 17 '23 13:02

Leonid Shifrin