Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You could use recursive trials.</p> <p>You would need at least the move count and to pass a copy of the vector. You'd also want to set a maximum move cutoff to set a limit to the breadth of branches coming out of at each node of the search tree. Note this is a "brute force" approach."</p> <p>Your general algorithm structure would be:</p> <pre><code>const int MAX_FLIPS=10; const unsigned int TREE_BREADTH=10; int run_recursion(std::vector&lt;std::vector&lt;bool&gt;&gt; my_grid, int current flips) { bool found = true; int temp_val = -1; int result = -1; //Search for solution with for loops; if true is found in grid, found=false; ... if ( ! found &amp;&amp; flips &lt; MAX_FLIPS ) { //flip coin. for ( unsigned int more_flips=0; more_flips &lt; TREE_BREADTH; more_flips++ ) { //flip one coin ... //run recursion temp_val=run_recursion(my_grid,flips+1) if ( (result == -1 &amp;&amp; temp_val != -1) || (temp_val != -1 &amp;&amp; temp_val &lt; result) ) result = temp_val; } } return result; } </code></pre> <p>...sorry in advance for any typos/minor syntax errors. Wanted to prototype a fast solution for you, not write the full code...</p> <p>Or easier still, you could just use a brute force of linear trials. Use an outer for loop would be number of trials, inner for loop would be flips in trial. On each loop you'd flip and check if you'd succeeded, recycling your success and flip code from above. Success would short circuit the inner loop. At the end of the inner loop, store the result in the array. If failure after max_moves, store -1. Search for the max value.</p> <p>A more elegant solution would be to use a multithreading library to start a bunch of threads flipping, and have one thread signal to others when it finds a match, and if the match is lower than the # of steps run thus far in another thread, that thread exits with failure.</p> <p>I suggest MPI, but CUDA might win you brownie points as it's hot right now.</p> <p>Hope that helps, good luck!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload