在序列/字符串中添加一位数字(0-9)会创建新的4位数字 [英] Adding one digit (0-9) to the sequence/string creates new 4 digits number

查看:118
本文介绍了在序列/字符串中添加一位数字(0-9)会创建新的4位数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过输入0-9键来找到一种破坏安全性的算法。密码为4位数字。保险箱将在其中将代码标识为键入的子字符串的位置打开。意思是,如果代码是 3456,那么下一次键入将打开保险箱: 123456。 (这只是意味着保险箱不会每输入4个键重新启动。)

I'm trying to find an algorithm which "breaks the safe" by typing the keys 0-9. The code is 4 digits long. The safe will be open where it identifies the code as substring of the typing. meaning, if the code is "3456" so the next typing will open the safe: "123456". (It just means that the safe is not restarting every 4 keys input).

是否存在一种算法,每次向序列添加一位数字时,它都会创建新的4位位数(字符串最后4位数字的新组合)?

Is there an algorithm which every time it add one digit to the sequence, it creates new 4 digits number (new combinations of the last 4 digits of the sequence\string)?

感谢,公里。

编辑(我几年前发布过):
问题是如何确保每次我将输入(一位数字)设置到保险箱时,都生成一个以前没有生成的新的4位代码。例如,如果保险箱获得3位数字的二进制代码,那么这应该是我的输入序列:

Editing (I post it years ago): The question is how to make sure that every time I set an input (one digit) to the safe, I generate a new 4 digit code that was not generated before. For example, if the safe gets binary code with 3 digits long then this should be my input sequence:

0001011100 

因为每输入一次,我都会得到一个以前未生成的新代码(3位长):

Because for every input I get a new code (3 digit long) that was not generated before:

000 -> 000
1 -> 001
0 -> 010
1 -> 101
1 -> 011
1 -> 111
0 -> 110
0 -> 100


推荐答案

我发现您的问题得到了缓解:

I found a reduction to your problem:

让我们通过以下方式定义有向图G =(V,E):

Lets define directed graph G = (V,E) in the following way:

V = {所有可能的组合

V = {all possible combinations of the code}.

E = {< u,v> |可以通过在u处添加1位数字(末尾)并删除第一位数字来获得v。

E = {< u,v > | v can be obtained from u by adding 1 digit (at the end), and delete the first digit}.

| V | = 10 ^ 4。

|V| = 10^4.

每个顶点的Din和Dout等于10 => | E | = 10 ^ 5。

Din and Dout of every vertex equal to 10 => |E| = 10^5.

您需要证明G中存在汉密尔顿循环-如果这样做,则可以证明存在解。

You need to prove that there is Hamilton cycle in G - if you do, you can prove the existence of a solution.

编辑1:

算法:


  1. 如上所述构造有向图G。

  1. Construct directed graph G as mentioned above.

计算汉密尔顿周期-{v1,v2,.., vn-1,v1}。

Calculate Hamilton cycle - {v1,v2,..,vn-1,v1}.

按v1中的每个数字。

X <-v1。

X <- v1.

而保险柜没有打开:

5.1 X< -汉密尔顿路径中X之后的下一个顶点。

5.1 X <- next vertex in the Hamilton path after X.

5.2按X中的最后一位数字。

5.2 press the last digit in X.

我们可以看到,因为我们使用汉密尔顿循环,所以我们从不重复相同的子字符串。 (最后4次按下)。

We can see that because we use Hamilton cycle, we never repeat the same substring. (The last 4 presses).

EDIT2:

当然是汉密尔顿路径足够。

Of course Hamilton path is sufficient.

这篇关于在序列/字符串中添加一位数字(0-9)会创建新的4位数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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