开发者

Concatenate list elements into a number in Mathematica

I开发者_StackOverflow社区 am trying to generate circular prime numbers in Mathematica 8.

A circular prime number is a number such that all rotations of its digits are prime

Eg. 197 is circular because 971, and 719, are primal too.

Now, in order to test if a prime number is circular, I generate all rotations. I do this as follows:

p = IntegerDigits[197];
Table[RotateLeft[p, n], {n, Length[p]}]

Which consequently returns

{{9, 7, 1}, {7, 1, 9}, {1, 9, 7}}

However this is where I get stuck. What I would like to do now is to grab the elements of each inner list and concatenate them together in a sequential order so that the output becomes this

{971, 719, 197}

So that I can test if all rotations satisfy PrimeQ[].

While I on the one hand could have this done by looping through the list, it seems to me as if there is a better way that I am just not realizing.


FromDigits is what you're looking for.

FromDigits /@ {{9, 7, 1}, {7, 1, 9}, {1, 9, 7}}
{971, 719, 197}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜