Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

Supplementing my previous question I decided to ask a new one which is more general.

So is given a natural even number $k$ and a function $f_k:\mathbb{N}_0\rightarrow\mathbb{N}_0:n\rightarrowtail(n \;\text{mod} \; k) \rightarrowtail \text{miracle} \rightarrowtail f_k(n)$ such that:

Here comes the miracle explanation (how functions acts):

  • $k = 2$

    0 -> 0
    1 -> 0
    
  • $k = 4$

    0 -> 0
    1 -> 1
    2 -> 1
    3 -> 0
    
  • $k = 6$

    0 -> 0
    1 -> 1
    2 -> 2
    3 -> 2
    4 -> 1
    5 -> 0
    
  • $k = 8$

    0 -> 0
    1 -> 1
    2 -> 2
    3 -> 3
    4 -> 3
    5 -> 2
    6 -> 1
    7 -> 0
    

If $k$ would be odd, it would be simple: $$f(n) = |\frac{k}{2} - |n - \frac{k}{2}|\;|$$ (fraction without decimal part). But for even $k$'s I can't figure out something, so could you please help me to express this function (must be something with modulo, absolute value, Gauss brackets of kind of this).

Thanks in advance!

Cheers

share|improve this question

1 Answer 1

up vote 0 down vote accepted

Just use $(k-1)/2$ instead of $k/2$: $$f(n)=\Bigg\lvert\frac{k-1}2-\bigg\lvert n-\frac{k-1}2\bigg\rvert\Bigg\rvert.$$

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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