OFFSET
0,3
LINKS
Moosa Nasir, Example of n = 11323.
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)
def A358647(n):
s = list(map(int, str(n)))
l, i = len(s), 0
for _ in range(l):
i = (i+s[i])%l
return s[i] # Chai Wah Wu, Nov 30 2022
CROSSREFS
KEYWORD
nonn,base,easy
AUTHOR
Moosa Nasir, Nov 24 2022
STATUS
approved
