[Scilab-users] [EXTERNAL] Count specific values in text file

P M p.muehlmann at gmail.com
Wed Feb 12 09:46:45 CET 2020


Hi,

Option 1:
You manually put a "." inside the file and run the script.
Since you only mentioned "pi" and "e" it's little efford.

Option 2:
You still can use csvRead even without having a "." as separator.
Note: Search range adapted to count only in digits behind the decimal sign.
You may change as you wish.

Best regards,
Philipp

// path to the txt filepath = 'pathToFile'// read the file as
stringpiAsString = csvRead(path, [],[],'string')// split the string at
'' (use no token) [piAsString] = strsplit(piAsString,'');// convert
string to doublepiDigits = strtod(piAsString);// search: how often
appears a certain value in a specific range within the
digitssearchRange = 100;searchVal = 1;// adapt the range, to search
only places behind the decimal sign
[locations] = find(piDigits(2:searchRange+1) == searchVal);//
uncomment if wished// printf("location \t number\n");// for i=
2:searchRange+1//     printf("%d \t %d \n", i-1, piDigits(i));//
endprintf("The number %d appears %d times in the first %d digits of
Pi\n",searchVal,length(locations),searchRange) ;printf("The number %d
appears at following locations: \n", searchVal);disp(locations');


Am Mi., 12. Feb. 2020 um 08:57 Uhr schrieb arctica1963 <
arctica1963 at gmail.com>:

> Hello Philipp
>
> Your suggestion is kind of what I am trying to do, but the text file is not
> a CSV structure. It is just a single, very big number on one row. A small
> chunk:
>
> 31415926535897932384626433832795028841971693993751058209749445923078164 etc
> (no spaces between digits)
>
> How best to load the text file and then count the number of occurrences of
> a
> specific digit (e.g. 1)? At the moment the file essentially contains a very
> big integer.
>
> Interested to see the best method of doing this.
>
> Thanks
>
>
>
>
>
> --
> Sent from:
> http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html
> _______________________________________________
> users mailing list
> users at lists.scilab.org
> http://lists.scilab.org/mailman/listinfo/users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20200212/75eba12f/attachment.htm>


More information about the users mailing list