about functions and modulo operator

Oct 2013
12
0
Hi i HAVE A TABLE:

n | f(n)
1 | 6
2 | 7
3 | 6
4 | 7
5 | 6

How can I express this with a mod operator?

f(n) = n mod what?

Is it possible?
Thanks
 
Last edited:

mathman

Forum Staff
May 2007
6,932
774
Restate your question. f(n)=n is not unique.
 

CRGreathouse

Forum Staff
Nov 2006
16,046
936
UTC -5
It looks like f(odd) = 6 and f(even) = 7 so you could write

f(n) = 7 - (n%2)

where % is the mod operator.
 
  • Like
Reactions: 1 person

Benit13

Math Team
Apr 2014
2,166
739
Glasgow
Just in case you don't know, the mod operator means "take the remainder when I divide two numbers"

When n=1, the remainder when 1 is divided by 2 is 1.
When n=2, the remainder when 2 is divided by 2 is 0.
When n=3, the remainder when 3 is divided by 2 is 1.
When n=4, the remainder when 4 is divided by 2 is 0.
...
 
  • Like
Reactions: 1 person