Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I saw your previous question on the same topic, and I start to work on it.<br> As you doesn't want the direct solution, I can provide you my reflexion about your problem, I guess it could help you. </p> <p>Some basic property :<br> 1. The number of movement is alway egal to the length of the list <strong>m = length A</strong><br> 2. The number of starting point is egal to the length of the head of the list <strong>n = length (head A)</strong><br> 3. The current position could never be negative, then :<br> - if the current position is egal to 0 you can either go down or right<br> - else you can go to left, down or right </p> <p>Which lead us to this pseudo code </p> <pre><code>generate_path :: [[Int]] -&gt; [[Int]] generate_path [] = [[]] generate_path A = ... -- You have to put something here where m = length A n = length (head A) </code></pre> <p>This things should look like something as this </p> <pre><code>move pos0 count0 | count0 == 0 = | pos0 == 0 = move (down count) ++ move (right count) | otherwise = move (left count) ++ move (down count) ++ move (right count) where count = count0 - 1 down = position0 left = position0 - 1 right = position0 + 1 </code></pre> <p>In fact keeping all of this in mind and adding the <strong>(!!)</strong> operator, we shouldn't be so far of the solution. To convince you play with <strong>A + list comprehension + !!</strong>, as </p> <pre><code>[A !! x !! y | x &lt;- [1..2], y &lt;- [0..2]] -- I take random range </code></pre> <p>Or play with another version : </p> <pre><code>[[A !! x !! y | x &lt;- [1..2]] | y &lt;- [0..2]]] -- I take random range </code></pre> <p>In fact you have two recursion the main one working on the parameter n = length (head A), you repeat the same action from 0 to (n-1) at (n-1) retrieve the result, this recursion embedded another one which work on m, repeat the same action from 0 to (m-1). </p> <p>Hope it help. Good luck.</p>
 

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