You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Szudzik配对算法存在重复映射问题:与Cantor配对对比验证

Szudzik配对算法出现重复映射问题

我尝试使用Szudzik配对算法替代Cantor配对算法,却发现该算法存在重复映射的情况。

示例代码

function szudzikPair(x, y)
{
    return (x >= y ? (x * x) + x + y : (y * y) + x);
}

console.log(szudzikPair(
127382263,
10902761));

console.log(szudzikPair(
127382263,
10902759));

console.log(szudzikPair(
127382263,
10902760));

function cantorPair(x, y) 
{
    return (0.5 * (x + y) * (x + y + 1)) + y;
}

console.log(cantorPair(
127382263,
10902761));

console.log(cantorPair(
127382263,
10902759));

console.log(cantorPair(
127382263,
10902760));

调用Szudzik配对算法处理上述三组不同的整数对,返回结果均为16226241065286192;而Cantor配对算法对相同整数对返回的结果各不相同,我原本预期Szudzik算法能像Cantor算法一样实现唯一映射。

实际输出

16226241065286192
16226241065286192
16226241065286192
9561374011385560
9561373734815512
9561373873100536

内容的提问来源于stack exchange,提问作者Barbara Epifanova

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 05:32:35