Answering some programming (for very beginners) questions in "Essentials of Programming in Mathematica" I came on the issue of whether a number is a divisor of its own right rotation.
Code below.
integerRotateRight[n_] := RotateRight[IntegerDigits[n]];
dividesItsRightRotationQ[n_] :=
If [Mod[FromDigits[integerRotateRight[n]], n] == 0, True, False];
set1 = Select[Range[10000000], dividesItsRightRotationQ]
which outputs.
{1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, \
99, 111, 222, 333, 444, 555, 666, 777, 888, 999, 1111, 2222, 3333, \
4444, 5555, 6666, 7777, 8888, 9999, 11111, 22222, 33333, 44444, \
55555, 66666, 77777, 88888, 99999, 102564, 111111, 128205, 142857, \
153846, 179487, 205128, 222222, 230769, 333333, 444444, 555555, \
666666, 777777, 888888, 999999, 1111111, 2222222, 3333333, 4444444, \
5555555, 6666666, 7777777, 8888888, 9999999}
ie mostly boring numbers but a few not boring ones.
For a laugh I reversed the process
integerRotateLeft[n_] := RotateLeft[IntegerDigits[n]]
dividesItsLeftRotationQ[n_] :=
If [Mod[FromDigits[integerRotateLeft[n]], n] == 0, True, False]
set2 = Select[Range[10000000], dividesItsLeftRotationQ]
{1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99, 111, \
222, 333, 444, 555, 666, 777, 888, 999, 1111, 2222, 3333, 4444, 5555, \
6666, 7777, 8888, 9999, 11111, 22222, 33333, 44444, 55555, 66666, \
77777, 88888, 99999, 102564, 111111, 128205, 142857, 153846, 179487, \
205128, 222222, 230769, 333333, 444444, 555555, 666666, 777777, \
888888, 999999, 1111111, 2222222, 3333333, 4444444, 5555555, 6666666, \
7777777, 8888888, 9999999}
again mostly boring numbers but one or two not so obvious ones.
What really intrigued me was this
Intersection [set1, set2]
{1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99, 111, \
222, 333, 444, 555, 666, 777, 888, 999, 1111, 2222, 3333, 4444, 5555, \
6666, 7777, 8888, 9999, 11111, 22222, 33333, 44444, 55555, 66666, \
77777, 88888, 99999, 111111, 142857, 222222, 333333, 444444, 555555, \
666666, 777777, 888888, 999999, 1111111, 2222222, 3333333, 4444444, \
5555555, 6666666, 7777777, 8888888, 9999999}
up to 10 million 142857 is the only number that divides its own right and left rotation. Why?
Is there a next one and if so when?
Chess