I have borrowed the following cyclic permutations list making function from here.
CyclicPermutations[list_] := Map[RotateRight[list, #] &, Range[Length[list]] - 1]
Using this function I make a list of cyclic permutations of the digits of some prime numbers as follows:
Table[CyclicPermutations[IntegerDigits[Prime[n]]], {n, 100, 101}]
{{{5, 4, 1}, {1, 5, 4}, {4, 1, 5}}, {{5, 4, 7}, {7, 5, 4}, {4, 7, 5}}}
Reconstructing the list of numbers using Map[f,list,levelspec]
and FromDigits
gives:
Map[FromDigits,Table[CyclicPermutations[IntegerDigits[Prime[n]]], {n, 100, 101}], 1]
{{514, 451, 145}, {574, 457, 745}}
The integers have been permuted again in the reconstruction. However, the following code does not permute them again at the cost of losing needed structure:
FromDigits/@Flatten[Table[CyclicPermutations[IntegerDigits[Prime[n]]], {n, 100, 101}], 1]
{541, 154, 415, 547, 754, 475}
I could partition this list properly but it would be very nice to keep the original nested structure.
edit:
I changed my function slightly to:
CyclicPermutations[list_]:=Table[RotateRight[list, n],{n, 1, Length[list]}]
An implementation of Project Euler # 35
count = 0;
Table[If[AllTrue[FromDigits/@CyclicPermutations[IntegerDigits[Prime[n]]],PrimeQ],count+=1],{n, 1, 78498}];
count
55