<div dir="ltr">Hi Samuel,<div><br></div><div>Further to your method, is there a way to vectorise the list output based on the indices?</div><div><br></div><div>One can access the elements as seq(1), seq(5) etc. I did look at list2vec(seq), but as documented this creates a single column vector. </div><div><br></div><div>Thanks</div><div><br></div><div>Lester</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, 15 Aug 2021 at 14:55, Samuel Gougeon <<a href="mailto:sgougeon@free.fr">sgougeon@free.fr</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
  
    
  
  <div>
    <div>Le 15/08/2021 à 11:28, Lester Anderson
      a écrit :<br>
    </div>
    <blockquote type="cite">
      
      <div dir="ltr">Hello Samuel,
        <div><br>
        </div>
        <div>The size of ns (number of steps) and seq (sequence of
          values) are variable depending on the integer input, and this
          seems to be one issue.</div>
      </div>
    </blockquote>
    <p>For this reason, seq must be a list, leading to</p>
    <pre style="font-family:Monospaced;font-style:normal"><span style="color:rgb(176,24,19)">function</span> <span style="color:rgb(74,85,219)">[</span><span style="color:rgb(131,67,16);font-weight:bold">ns</span><span style="color:rgb(0,0,0)">, </span><span style="color:rgb(131,67,16);font-weight:bold">seq</span><span style="color:rgb(74,85,219)">] </span><span style="color:rgb(92,92,92)">= </span><span style="color:rgb(0,0,0);text-decoration:underline">collatz</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(131,67,16);font-weight:bold">p</span><span style="color:rgb(74,85,219)">)</span>
    <span style="color:rgb(131,67,16);font-weight:bold">seq</span> <span style="color:rgb(92,92,92)">=</span> <span style="color:rgb(131,67,16);font-weight:bold">p</span>
    <span style="color:rgb(160,32,240)">while</span> <span style="color:rgb(218,112,214)">%T</span>
        <span style="color:rgb(160,32,240)">if</span> <span style="color:rgb(174,92,176);text-decoration:underline">pmodulo</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(131,67,16);font-weight:bold">p</span><span style="color:rgb(0,0,0)">, </span><span style="color:rgb(188,143,143)">2</span><span style="color:rgb(74,85,219)">)</span>
            <span style="color:rgb(131,67,16);font-weight:bold">p</span> <span style="color:rgb(92,92,92)">=</span> <span style="color:rgb(131,67,16);font-weight:bold">p</span><span style="color:rgb(92,92,92)">*</span><span style="color:rgb(188,143,143)">3</span><span style="color:rgb(92,92,92)">+</span><span style="color:rgb(188,143,143)">1</span>
        <span style="color:rgb(160,32,240)">else</span>
            <span style="color:rgb(131,67,16);font-weight:bold">p</span> <span style="color:rgb(92,92,92)">=</span> <span style="color:rgb(131,67,16);font-weight:bold">p</span><span style="color:rgb(92,92,92)">/</span><span style="color:rgb(188,143,143)">2</span>
        <span style="color:rgb(160,32,240)">end</span>
        <span style="color:rgb(131,67,16);font-weight:bold">seq</span> <span style="color:rgb(92,92,92)">=</span> <span style="color:rgb(74,85,219)">[</span><span style="color:rgb(131,67,16);font-weight:bold">seq</span> <span style="color:rgb(131,67,16);font-weight:bold">p</span><span style="color:rgb(74,85,219)">]</span>
        <span style="color:rgb(160,32,240)">if</span> <span style="color:rgb(131,67,16);font-weight:bold">p</span><span style="color:rgb(92,92,92)">==</span><span style="color:rgb(188,143,143)">1</span>
            <span style="color:rgb(131,67,16);font-weight:bold">ns</span> <span style="color:rgb(92,92,92)">=</span> <span style="color:rgb(50,185,185)">length</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(131,67,16);font-weight:bold">seq</span><span style="color:rgb(74,85,219)">)</span>
            <span style="color:rgb(95,158,160)">break</span>
        <span style="color:rgb(160,32,240)">end</span>
    <span style="color:rgb(160,32,240)">end</span>
<span style="color:rgb(176,24,19)">endfunction</span>

<span style="color:rgb(160,32,240)"><span style="color:rgb(0,0,0)">prime</span> <span style="color:rgb(92,92,92)">=</span> <span style="color:rgb(174,92,176);text-decoration:underline">primes</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(188,143,143)">20</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(0,0,0)">;</span>
<span style="color:rgb(74,85,219)">[</span><span style="color:rgb(0,0,0)">ns</span><span style="color:rgb(0,0,0)">,</span> <span style="color:rgb(0,0,0)">seq</span><span style="color:rgb(74,85,219)">]</span> <span style="color:rgb(92,92,92)">=</span> <span style="color:rgb(74,85,219)">(</span><span style="color:rgb(74,85,219)">[</span><span style="color:rgb(74,85,219)">]</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(50,185,185)"> list</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(0,0,0)">;</span>
<span style="color:rgb(176,24,19)"></span>
for</span> <span style="color:rgb(0,0,0)">i</span> <span style="color:rgb(92,92,92)">=</span> <span style="color:rgb(188,143,143)">1</span><span style="color:rgb(255,170,0)">:</span><span style="color:rgb(50,185,185)">length</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(0,0,0)">prime</span><span style="color:rgb(74,85,219)">)</span>
    <span style="color:rgb(74,85,219)">[</span><span style="color:rgb(0,0,0)">ns</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(0,0,0)">i</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(0,0,0)">,</span> <span style="color:rgb(0,0,0)">seq</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(0,0,0)">i</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(74,85,219)">]</span> <span style="color:rgb(92,92,92)">=</span> <span style="color:rgb(174,92,176);text-decoration:underline">collatz</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(0,0,0)">prime</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(0,0,0)">i</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(0,0,0)">;</span>
<span style="color:rgb(160,32,240)">end

<font color="#400040">--> ns'
 ans  =

   2.   8.   6.   17.   15.   10.   13.   21.

--> seq
 seq  = 

  (1) = [2,1]
  (2) = [3,10,5,16,8,4,2,1]
  (3) = [5,16,8,4,2,1]
  (4) = [7,22,11,34,17,52,26,13,40,20,10,5,16,8,4,2,1]
  (5) = [11,34,17,52,26,13,40,20,10,5,16,8,4,2,1]
  (6) = [13,40,20,10,5,16,8,4,2,1]
  (7) = [17,52,26,13,40,20,10,5,16,8,4,2,1]
  (8) = [19,58,29,88,44,22,11,34,17,52,26,13,40,20,10,5,16,8,4,2,1]

</font></span></pre>
    <p>Samuel</p>
    <p><br>
    </p>
  </div>

_______________________________________________<br>
users mailing list<br>
<a href="mailto:users@lists.scilab.org" target="_blank">users@lists.scilab.org</a><br>
<a href="http://lists.scilab.org/mailman/listinfo/users" rel="noreferrer" target="_blank">http://lists.scilab.org/mailman/listinfo/users</a><br>
</blockquote></div>