Note that there are some explanatory texts on larger screens.

plurals
  1. POImprovement of the Greedy Algorithm
    primarykey
    data
    text
    <p>I've been working on an abstract chess algorithm using Haskell (trying to expand my understanding of different paradigms), and I've hit a challenge that I've been pondering about for weeks.</p> <p>Here's the problem:</p> <blockquote> <p>Given a board (represented by a list of lists of integers; each integer represents a subsequent point value), with dimensions n x n, determine the path that provides the most points. If there is a tie for best path, return either of them.</p> </blockquote> <p>Here are the specifics:</p> <pre><code>A = [[5,4,3,1],[10,2,1,0],[0,1,2,0],[2,3,4,20]] </code></pre> <p>which renders as: </p> <pre><code>R1: 5 4 3 1, R2: 10 2 1 0, R3: 0 1 2 0, R4: 2 3 4 20. </code></pre> <p>The rules are: </p> <ol> <li><p>You may start anywhere on the top row </p></li> <li><p>You may move one square at a time, either straight down, down-left (diagonal) , or down-right (diagonal). </p></li> <li><p>The output must be a tuple of integers. </p></li> </ol> <p>First element is a list representing the columns vs. row, and the second element is the total number of points. Eg. for the above board, the best solution is to travel from top-left (5) and go diagonally for the remaining steps (until the 20 point square). This would result in the tuple <code>([1,2,3,4], 29)</code>. </p> <p>Remember, this is all in Haskell so it is a functional-paradigm recursive problem. At first, I was thinking about using the greedy algorithm, that is, choosing the highest value in r1, and recursing through comparing the next 3 possibilities; choosing the highest of the 3. However, the downfall is that the greedy algorithm doesn't have the ability to see potential ahead of the next row. </p> <p>How would I go about this? I'm not looking for code per se, since I enjoy solving things on my own. However, pseudocode or some algorithmic guidance would be much appreciated!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    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