A bijection between numbers and pairs of numbers
Every once in a while I am faced with someone who denies that the rational numbers (or fractions, or pairs of integers) can be put into a bijective correspondence with natural numbers. To deal with the situation, I coded up the bijection. So now I can just say: "Really? Interesting. Please provide a pair of numbers
(i,j) which is not enumerated by
f, as defined in my gist." I am still waiting for a valid counter-example.
Anyhow, here is a demo of
g at work. I am using the Python version, but a Haskell variant is included as well.
The 100-th pair is:
>>> f(100) (10, 4)