Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The idea is the same, represent the problem as a states <a href="http://en.wikipedia.org/wiki/Graph_%28mathematics%29" rel="nofollow">graph</a>, and run <a href="http://en.wikipedia.org/wiki/Shortest_path_problem" rel="nofollow"><strong>shortest path</a> algorithm</strong>.</p> <p>If the efficiency of the algorithm is important, you might want an informed algorithm -such as <a href="http://en.wikipedia.org/wiki/A%2a_search_algorithm" rel="nofollow"><strong>A* algorithm</strong></a>, which is expected to be pretty fast (relative to the alternatives) with a good <a href="http://en.wikipedia.org/wiki/Admissible_heuristic" rel="nofollow">admissible heuristic function</a>. <br>A slower though simpler solution can be running a <a href="http://en.wikipedia.org/wiki/Breadth-first_search" rel="nofollow"><strong>BFS</strong></a>.</p> <p>Both algorithms (A*, BFS) are both <strong>complete</strong> (always finds a solutuion, if one exists) and <strong>optimal</strong> (finds shortest path).</p> <p>Also note, you can use <strong>macros to learn "good" series of moves</strong>, to get the algorithm faster. Ignore this improvement until you implement a working (though slow) solution.</p> <hr> <p><strong>EDIT:</strong> Coding guidelines: <br>Look at the problem as a graph: The graph will be <code>G=(V,E)</code> where <code>V = { all possible states}</code> and <code>E = { (u,v) | can move from state u to state v within a single step }</code></p> <p>Now, with this graph - you have a starting position (the source, which is given as input) and a target (a sorted puzzle). Start a BFS or A* (have a look at the pseudo code of these in the attached wikipedia links), to find a path from the source to the destination. You should start with BFS - it is simpler. <br>The path returned by the shortest path algorithm is identical to the series of moves you will have to do in order to get from the starting board to the target.</p> <p>Note: You do not need to create the actual graph! you just need a to hold the starting node (source) - and create its vertex, and have a <code>successors:V-&gt;2^V</code> function, that gives you the successors for each vertex (formally: <code>successors(v) = { (v,u) | (v,u) is in E }</code> ). This way, you can build the relevant part of the graph on the fly.</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. 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