問題描述
在 Mathematica 中將列表元素連接成一個數字 (Concatenate list elements into a number in Mathematica)
I 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.
參考解法
方法 1:
FromDigits
is what you're looking for.
FromDigits /@ {{9, 7, 1}, {7, 1, 9}, {1, 9, 7}}
{971, 719, 197}