Skip to content

Instantly share code, notes, and snippets.

@albertotb
albertotb / pair.py
Created April 21, 2021 12:02
Szudzik pairing for negative numbers
import math
from typing import Tuple
def pair_negative(x: int) -> int:
return 2 * x if x >= 0 else -2 * x - 1
def unpair_negative(z: int) -> int:
return int(z / 2) if z % 2 == 0 else int((z + 1) / -2)
def pair_szudzik(x: int, y: int) -> int: