用素数比较字谜 [英] Comparing anagrams using prime numbers

查看:142
本文介绍了用素数比较字谜的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有试图查看两个唯一字符串互为字谜的问题。我曾考虑过第一个解决方案是将两个字符串进行排序,看看他们是彼此相等。

There is the problem of trying to see if two unique strings are anagrams of each other. The first solution that I had considered would be to sort both strings and see if they were equal to each other.

我一直在考虑另一种解决方案,我想讨论如果同样是可行的。

I have been considering another solution and I would like to discuss if the same would be feasible.

我们的想法是将一个数值分配给每个字符,并概括起来,这样一个独特的字符集将产生一个独特的价值。当我们正在测试字谜,我们不介意ASDF和ADSF的校验码是相同的 - 事实上,我们要求它是这样。然而字符串AA和b的校验不应该相等。

The idea would be to assign a numerical value to each character and sum it up such that a unique set of characters would produce a unique value. As we are testing for anagrams, we do not mind if the checksum of "asdf" and "adsf" are the same -- in fact, we require it to be that way. However the checksum of strings "aa" and "b" shouldn't be equal.

我正在考虑分配第一52素数以字母a到到Z,Z,然后选择A(假设我们只有字母)。

I was considering assigning the first 52 prime numbers to alphabets "a" through "z" and then "A" through "Z"(assume we only have alphabets).

上面的方案将打破,如果在所述一组52的素数的任意两个或更多个素数的总和可能导致现有的在该组的另一素

The above scheme would break if the sum of any two or more primes in the set of 52 primes could result in another prime existing in the set.

我的疑惑是: -

  1. 有没有编号方案,将satify我的要求是什么?
  2. 在我不能确定所涉及的数学;是有可能证明/是那里,表明任何证明的两个或两个以上的质数集合中的第一个52质数的总和具有至少一个值,该值存在于同一组?

感谢。

推荐答案

使用乘法,而不是加法。素数是乘法独特的,而不是加法独一无二的。

Use multiplication instead of addition. Primes are "multiplicatively unique", but not "additively unique".

这篇关于用素数比较字谜的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆