<div dir="ltr"><div>Hi,</div><div><br></div><div>Option 1:</div><div>You manually put a "." inside the file and run the script.</div><div>Since you only mentioned "pi" and "e" it's little efford.<br></div><div><br></div><div>Option 2:<br></div><div>You still can use csvRead even without having a "." as separator.</div><div>Note: Search range adapted to count only in digits behind the decimal sign.</div><div>You may change as you wish.</div><div><br></div><div>Best regards,</div><div>Philipp<br></div><div></div><div><pre style="font-family:Monospaced;font-style:normal"><span style="color:rgb(100,174,100);font-style:italic">// path to the txt file</span>
<span style="color:rgb(0,0,0)">path</span> <span style="color:rgb(92,92,92)">=</span> <span style="color:rgb(188,143,143)">'</span><span style="color:rgb(188,143,143)">pathToFile</span><span style="color:rgb(188,143,143)">'</span>
<span style="color:rgb(100,174,100);font-style:italic">// read the file as string</span>
<span style="color:rgb(0,0,0)">piAsString</span> <span style="color:rgb(92,92,92)">=</span> <span style="color:rgb(50,185,185)">csvRead</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(0,0,0)">path</span><span style="color:rgb(0,0,0)">,</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(74,85,219)">[</span><span style="color:rgb(74,85,219)">]</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(188,143,143)">'</span><span style="color:rgb(188,143,143)">string</span><span style="color:rgb(188,143,143)">'</span><span style="color:rgb(74,85,219)">)</span>
<span style="color:rgb(100,174,100);font-style:italic">// split the string at '' (use no token) </span>
<span style="color:rgb(74,85,219)">[</span><span style="color:rgb(0,0,0)">piAsString</span><span style="color:rgb(74,85,219)">]</span> <span style="color:rgb(92,92,92)">=</span> <span style="color:rgb(50,185,185)">strsplit</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(0,0,0)">piAsString</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(188,143,143)">'</span><span style="color:rgb(188,143,143)">'</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(0,0,0)">;</span>
<span style="color:rgb(100,174,100);font-style:italic">// convert string to double</span>
<span style="color:rgb(0,0,0)">piDigits</span> <span style="color:rgb(92,92,92)">=</span> <span style="color:rgb(50,185,185)">strtod</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(0,0,0)">piAsString</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(0,0,0)">;</span>
<span style="color:rgb(100,174,100);font-style:italic">// search: how often appears a certain value in a specific range within the digits</span>
<span style="color:rgb(0,0,0)">searchRange</span> <span style="color:rgb(92,92,92)">=</span> <span style="color:rgb(188,143,143)">100</span><span style="color:rgb(0,0,0)">;</span>
<span style="color:rgb(0,0,0)">searchVal</span> <span style="color:rgb(92,92,92)">=</span> <span style="color:rgb(188,143,143)">1</span><span style="color:rgb(0,0,0)">;</span>
<span style="color:rgb(100,174,100);font-style:italic">// adapt the range, to search only places behind the decimal sign<br></span><span style="color:rgb(74,85,219)">[</span><span style="color:rgb(0,0,0)">locations</span><span style="color:rgb(74,85,219)">]</span> <span style="color:rgb(92,92,92)">=</span> <span style="color:rgb(50,185,185)">find</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(0,0,0)">piDigits</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(188,143,143)">2</span><span style="color:rgb(255,170,0)">:</span><span style="color:rgb(0,0,0)">searchRange</span><span style="color:rgb(92,92,92)">+</span><span style="color:rgb(188,143,143)">1</span><span style="color:rgb(74,85,219)">)</span> <span style="color:rgb(92,92,92)">==</span> <span style="color:rgb(0,0,0)">searchVal</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(0,0,0)">;</span>
<span style="color:rgb(100,174,100);font-style:italic">// uncomment if wished</span>
<span style="color:rgb(100,174,100);font-style:italic">// printf(</span><span style="color:rgb(100,174,100);font-style:italic">"</span><span style="color:rgb(100,174,100);font-style:italic">location \t number\n</span><span style="color:rgb(100,174,100);font-style:italic">"</span><span style="color:rgb(100,174,100);font-style:italic">);</span>
<span style="color:rgb(100,174,100);font-style:italic">// for i= 2:searchRange+1</span>
<span style="color:rgb(100,174,100);font-style:italic">//     printf(</span><span style="color:rgb(100,174,100);font-style:italic">"</span><span style="color:rgb(100,174,100);font-style:italic">%d \t %d \n</span><span style="color:rgb(100,174,100);font-style:italic">"</span><span style="color:rgb(100,174,100);font-style:italic">, i-1, piDigits(i));</span>
<span style="color:rgb(100,174,100);font-style:italic">// end</span>
<span style="color:rgb(50,185,185)">printf</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(188,143,143)">"</span><span style="color:rgb(188,143,143)">The number %d appears %d times in the first %d digits of Pi\n</span><span style="color:rgb(188,143,143)">"</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(0,0,0)">searchVal</span><span style="color:rgb(0,0,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)">locations</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(0,0,0)">searchRange</span><span style="color:rgb(74,85,219)">)</span> <span style="color:rgb(0,0,0)">;</span>
<span style="color:rgb(50,185,185)">printf</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(188,143,143)">"</span><span style="color:rgb(188,143,143)">The number %d appears at following locations: \n</span><span style="color:rgb(188,143,143)">"</span><span style="color:rgb(0,0,0)">,</span> <span style="color:rgb(0,0,0)">searchVal</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(0,0,0)">;</span>
<span style="color:rgb(50,185,185)">disp</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(0,0,0)">locations</span><span style="color:rgb(92,92,92)">'</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(0,0,0)">;</span><span style="color:rgb(0,0,0)"></span></pre> </div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Am Mi., 12. Feb. 2020 um 08:57 Uhr schrieb arctica1963 <<a href="mailto:arctica1963@gmail.com">arctica1963@gmail.com</a>>:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hello Philipp<br>
<br>
Your suggestion is kind of what I am trying to do, but the text file is not<br>
a CSV structure. It is just a single, very big number on one row. A small<br>
chunk:<br>
<br>
31415926535897932384626433832795028841971693993751058209749445923078164 etc<br>
(no spaces between digits)<br>
<br>
How best to load the text file and then count the number of occurrences of a<br>
specific digit (e.g. 1)? At the moment the file essentially contains a very<br>
big integer.<br>
<br>
Interested to see the best method of doing this.<br>
<br>
Thanks <br>
<br>
<br>
<br>
<br>
<br>
--<br>
Sent from: <a href="http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html" rel="noreferrer" target="_blank">http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html</a><br>
_______________________________________________<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>