|
|
A358647
|
|
Final digit reached by traveling right (with wraparound) through the digits of n. Each move steps right k places, where k is the digit at the beginning of the move. Moves begin at the most significant digit and d moves are made, where d is the number of digits in n.
|
|
2
|
|
|
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 1, 4, 1, 6, 1, 8, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 3, 2, 3, 4, 3, 6, 3, 8, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 5, 2, 5, 4, 5, 6, 5, 8, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 0, 7, 2, 7, 4, 7, 6, 7, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 0, 9, 2, 9, 4, 9, 6, 9, 8, 9
(list;
graph;
refs;
listen;
history;
text;
internal format)
|
|
|
OFFSET
|
0,3
|
|
LINKS
|
|
|
EXAMPLE
|
For n = 11323, start at the most significant digit, which is 1.
On move 1, travel 1 unit right, reaching the second digit 1.
On move 2, travel 1 unit right, reaching the middle digit 3.
On move 3, travel 3 units right (wrapping around), reaching the most significant 1 digit again.
On move 4, travel 1 unit right, reaching the second digit 1 (again).
On move 5, travel 1 unit right, reaching the middle digit 3 (again).
Thus, a(11323) = 3.
|
|
PROG
|
(C++)
int a(int n)
{
int n2 = n;
int size = 0; do { n2 /= 10; size++; } while (n2 != 0);
int * nums = new int[size];
for(int i = size - 1; i >= 0; i--)
{
nums[i] = n % 10;
n /= 10;
}
int currentIndex = 0;
for (int j = 0; j < size; j++)
{
currentIndex += nums[currentIndex];
currentIndex %= size;
}
int returnVal = nums[currentIndex];
delete[] nums;
return returnVal;
}
(Python)
s = list(map(int, str(n)))
l, i = len(s), 0
for _ in range(l):
i = (i+s[i])%l
|
|
CROSSREFS
|
|
|
KEYWORD
|
nonn,base,easy
|
|
AUTHOR
|
|
|
STATUS
|
approved
|
|
|
|