How do you create an operation for circular indices of a vector?

26 Views Asked by At

So I am trying to construct a way to find the next X letters (using the ASCII codes). But it is circular such that the next letter after Z is A. So Z+1 would be A.

So basically it is an array (or vector) that goes from 65 to 90. The 66th element is the 66th element, 90th element is the 90th element, and so on. But the 91st element is actually the 65th element, 92nd is 66th, and so on.

I tried so many different combinations of modulo and addition operations, and couldn't figure out a "key" operation that would work. I don't even know how to word this question to Google for it.

Is it even possible to find such an operation?

1

There are 1 best solutions below

2
On BEST ANSWER

Why do you want this to be an vector? Make a function

$$f(x)=65 + \left((x - 65 )\bmod 26\right)$$

You can see, if $65 \leq a \leq 90$, you have $f(a)=a$, but for example $f(91)=65$, and so on.