Bacco's answer seems to me to be the only correct way, although some details escape me. Its sequence is:
{ i, se n == 0;
seq(n) = { seq(n-1)+2, se n % 2 == 1;
{ seq(n-1)+4, se n % 2 == 0.
That is, i
, i+2
, i+6
, i+8
, i+12
, ... This sequence can be simplified to:
i + 0*3 - 0,
i + 1*3 - 1,
i + 2*3 - 0,
i + 3*3 - 1,
i + 4*3 - 0,
...
Where each term, then, is equal to i + n*3 - n%2
. i.e. "go from 3 to 3, subtracting 1 from the odd terms". One way to implement this would be:
for j in [i + n*3 - n%2 for n in range(0, limite_superior)]:
print(j)
Where limite_superior
is n
, such that i + n*3 - n%2 >= len(message)
, i.e.:
n*3 - n%2 >= len(message) - i
n*3 >= len(message) - i + n%2
n >= (len(message) - i + n%2)/3
But Bacco's solution is simpler and more elegant - just pay attention to the difference between% s and even% s (in one case the first deviation will be i
, the other will be 2
). >