0
$\begingroup$

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?

$\endgroup$
1
$\begingroup$

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.

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ Oh it's because 65...90 are the indices of the vector. It's not a vector itself. But your function works, so thank you! :) $\endgroup$ – Jay Nov 12 '14 at 3:53
  • $\begingroup$ Oh, I see. Good! $\endgroup$ – Alexander Gruber Nov 12 '14 at 3:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.