[Tutor] Cantor pairing in three dimensions?

Steven D'Aprano steve at pearwood.info
Tue Dec 24 04:15:35 CET 2013


On Mon, Dec 23, 2013 at 10:32:14AM -0800, Danny Yoo wrote:
> I've got a puzzle: so there's a well-known function that maps the
> naturals N to N^2: it's called Cantor pairing:
> 
>     http://en.wikipedia.org/wiki/Pairing_function
[...]
> So here's the question: is there an analogy of the Cantor pairing
> function that maps N to N^3?

The Wikipedia article talks about generalizing the function so as to 
map N^k -> N for any integer k >= 1, so I would say so.

The mapping from N^3 -> N seems to be called the tripling function. Try 
this to start:

http://szudzik.com/ElegantPairing.pdf


Translating the Mathematica code into Python should be straight-forward.



-- 
Steven


More information about the Tutor mailing list