Adding one digit (0-9) to the sequence/string creates new 4 digits number

前端 未结 3 1313
再見小時候
再見小時候 2021-01-14 15:31

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

3条回答
  •  感动是毒
    2021-01-14 15:59

    Here in summary is the problem I think you are trying to solve and some explanation on how i might approach solving it. http://www.cs.swan.ac.uk/~csharold/cpp/SPAEcpp.pdf

    You have to do some finessing to make it fit into the chinese post man problem however... Imagine solving this problem for the binary digits, three digits strings. Assume you have the first two digits, and ask your self what are my options to move to? (In regards to the next two digit string?) You are left with a Directed Graph.

     /-\
    /   V    
    \-  00 ----> 01
          ^  /   ^|
           \/    ||
           /\    ||
          V  \   |V
     /-- 11 ---> 10 
     \   ^         
      \-/
    

    Solve the Chinese Postman, you will have all combinations and will form one string The question is now, is the Chinese postman solvable? There are algorithms which determine weather or not a DAG is solvable for the CPP, but i don't know if this particular graph is necessarily solvable based on the problem alone. That would be a good thing to determine. You do however know you could find out algorithmically weather it is solvable and if it is you could solve it using algorithms available in that paper (I think) and online.

    Every vertex here has 2 incoming edges and 2 outgoing edges. There are 4 (2^2) vertexes.

    In the full sized problem there are 19683( 3 ^ 9 ) vertexs and every vertex has 512 ( 2 ^ 9 ) out going and incoming vertexes. There would be a total of

    19683( 3 ^ 9 ) x 512 (2 ^ 9) = 10077696 edges in your graph. 
    

    Approach to solution:

    1.) Create list of all 3 digit numbers 000 to 999.
    2.) Create edges for all numbers such that last two digits of first number match first
    two digits of next number. 
    
    ie 123 -> 238 (valid edge) 123 -> 128 (invalid edge)
    
    3.) use Chinese Postman solving algorithmic approaches to discover if solvable and
    solve
    

提交回复
热议问题