Sequence That increases and then decreases using Modular Arithmetic

834 Views Asked by At

I'm trying to find a simple formula for a periodic sequence like this:

$$ 0,1,2,3,4,3,2,1,0...$$

I've figured it out for the increasing part of the sequence by using a modulo operator:

$$ i\ mod \ 5 $$

In that way, I have the desired upper and lower bound and it's periodic. The above formula gives me a sequence:

$$0,1,2,3,4,0,1,2,3...$$

Which is close. What change do I have to make to $$ i\ mod\ 5$$ in order for the sequence to decrease?

Thanks in advance!

1

There are 1 best solutions below

1
On BEST ANSWER

How about $4-\mid (i\%8)-4 \mid$. (Here $\%$ is the mod operator.) I think this gives the sequence $0,1,2,3,4,3,2,1,0,1,2,3,4,...$