且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何处理数字猜谜游戏(带扭曲)算法?

更新时间:2023-02-02 19:39:25

我们将结合图形理论和概率:

We'll combine graph-theory and probability:

在第1天,打造一个集所有可行的解决方案。让我们将解决方案表示为A1 = {a1(1),a1(2),...,a1(n)}。

On the 1st day, build a set of all feasible solutions. Lets denote the solutions set as A1={a1(1), a1(2),...,a1(n)}.

第二天你可以再次构建解决方案集A2。

On the second day you can again build the solutions set A2.

现在,对于A2中的每个元素,您需要检查是否可以从A1的每个元素到达(给定x%公差)。如果是这样 - 将A2(n)连接到A1(m)。如果无法从A1(m)中的任何节点到达它 - 您可以删除此节点。

Now, for each element in A2, you'll need to check if it can be reached from each element of A1 (given x% tolerance). If so - connect A2(n) to A1(m). If it can't be reached from any node in A1(m) - you can delete this node.

基本上我们正在构建一个连接的有向非循环图。

Basically we are building a connected directed acyclic graph.

图表中的所有路径都具有相同的可能性。只有当存在从Am到Am + 1的单个边缘时(从Am中的节点到Am + 1中的节点),才能找到精确解。

All paths in the graph are equally likely. You can find an exact solution only when there is a single edge from Am to Am+1 (from a node in Am to a node in Am+1).

当然,某些节点出现在比其他节点更多的路径中。可以根据包含该节点的路径数直接推导出每个节点的概率。

Sure, some nodes appear in more paths than other nodes. The probability for each node can be directly deduced based on the number of paths that contains this node.

通过为每个节点分配权重,该权重等于路径数导致这个节点,没有必要保留所有历史记录,但只需要保留前一天。

By assigning a weight to each node, which equals to the number of paths that leads to this node, there is no need to keep all history, but only the previous day.

另外,看看 non-negative-values linear diphantine equation - 我问的一个问题前一阵子。接受的答案是在每一步中enumarte所有组合的好方法。

Also, have a look at non-negative-values linear diphantine equations - A question I asked a while ago. The accepted answer is a great way to enumarte all combos in each step.