Tuesday, February 1, 2011

Hamiltonian path count (Quora coding challenge)


I found the following programming challenge at quora.


Datacenter Cooling (Read more)

We have some rooms in our datacenter, and we need to connect them all with a single cooling duct.
Here are the rules:

The datacenter is represented by a 2D grid.
Rooms we own are represented by a 0.

Read more
.....
...


This problem amounts to count the number of Hamiltonian paths in a graph.
I wrote a small program to compute them, it runs in less than 45 seconds.
The code is (hidden) below.


Show the code.




Show the C++ code.

1 comment:

  1. Here is an algorithm I transcribed for the Hamiltonian Circuit. E-mail if it works for you: marty dot musatov at gmail dot com. Thank you.
    // begin[0]
    // /* The following for-loop is the guessing stage*/
    // for i=1 to n do
    // X[i] := choose(i);
    // endfor
    //
    //
    // /* Next is the verification stage */
    // for i=1 to n do
    // for j=i+1 to n do
    // if X[i] = X[j] then
    // return(no);
    // endif
    // endfor
    // endfor
    // for i=1 to n-1 do
    // if (X[i],X[i+1]) is not an edge then
    // return(no);
    // endif
    // endfor
    // if (X[n],X[1]) is not an edge then
    // return(no);
    // endif
    //
    // return(yes);
    // end[1]

    ReplyDelete