在 Mathematica 7 中连接两个整数 [英] Concatenate two integers in Mathematica 7

查看:23
本文介绍了在 Mathematica 7 中连接两个整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Mathematica 7 中连接两个正整数的最有效方法是什么?

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

cc[123, 4567] >> 1234567

如果超过两个呢?

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

推荐答案

对于许多整数,这将比您的上一个解决方案稍微快一点:

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@#&

基于 IntegerStringListable.

这篇关于在 Mathematica 7 中连接两个整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆