Need help in building efficient exhaustive search algorithm

我是研究僧i 提交于 2019-12-02 00:32:55

问题


There are a 10 buttons. These buttons can unlock the lock if pressed in correct order (5 presses in sequence). Every button press triggers unlock check.

Example: "password" is 123456 and I press buttons 0 1 2 3 4 5 6 I unlock the lock from 6th button press.

I need to design algorithm that tries all possible combinations in the most efficient way (i.e. minimum amount of buttons should be pressed).

I can interpret button number as digit and number of pressed button in sequence as digit position and then try all 99999 combinations in attempt to unlock the lock but I feel that there is a more efficient algorithm to do that.

Is there something I can do to optimize this search?


回答1:


To optimize a brute-force attack on a lock, you can use De Bruijn sequences.

The sequence can be used to shorten a brute-force attack on a PIN-like code lock that does not have an "enter" key and accepts the last n digits entered. For example, a digital door lock with a 4-digit code would have B(10, 4) solutions, with length 10,000. Therefore, only at most 10,000 + 3 = 10,003 (as the solutions are cyclic) presses are needed to open the lock. Trying all codes separately would require 4 × 10,000 = 40,000 presses.



来源:https://stackoverflow.com/questions/12211425/need-help-in-building-efficient-exhaustive-search-algorithm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!