Skip to content

Instantly share code, notes, and snippets.

View PatrikMelanderVing's full-sized avatar

Patrik Melander PatrikMelanderVing

View GitHub Profile
@PatrikMelanderVing
PatrikMelanderVing / CantorPairUtility.cs
Created January 5, 2022 08:43 — forked from GibsS/CantorPairUtility.cs
Simple C# class to calculate Cantor's pairing function
using System;
public static class CantorPairUtility {
public static int CantorPair(int x, int y) {
return (((x + y) * (x + y + 1)) / 2) + y;
}
public static void ReverseCantorPair(int cantor, out int x, out int y) {
var t = (int) Math.Floor((-1 + Math.Sqrt(1 + 8 * cantor)) / 2);