Give an example of a real function so that every rational is a strict local minimum

I think that the function that sends any irrational number on $1$ and sends a rational $\frac{p}q$ (where the fraction is irreducible) on $1-\frac1q$ does the job. Given any rational number $\frac{p}q$, you can always find a neighborhood so that any rational number has a denominator bigger than $q$


Here's a pretty direct hint. If there were only rationals, the function could be defined as the denominator in lowest terms, because everything nearby enough would have a larger denominator. If we want to also define it on the irrationals this wouldn't work. However, we can compress the positive integers into $[0,1)$ in an order preserving way, then we can make the function $1$ on the irrationals.