Learn R Programming

PPRL (version 0.3.8)

ElegantPairingInt: Elegant Pairing

Description

Unordered Pairing Function creating a new unique integer from two input integers.

Usage

ElegantPairingInt(int1, int2)

Value

The function outputs a single non-negative integer that is uniquely associated with that unordered pair.

Arguments

int1

first integer to be paired.

int2

second integer to be paired.

Details

With two of non-negative integers x and y as an input, the pairing is computed as:

$$elegantPairing(x, y) = (x * y) + floor ((|x - y| - 1)^2) / 4)$$

The function is commutative. x and y have to be non-negative integers.

See Also

ElegantPairingVec

Examples

Run this code

ElegantPairingInt(2, 3)

Run the code above in your browser using DataLab