I have a .txt file that contains a 500 million digit binary representation of Pi.
I need to use a string representation of that in my program. I also need to be able to search it for substrings and the like – in other words, I need to be able to treat it like a normal sized string. I’ll be trying to find a lot of substrings so speed is necessary.
My initial logic was to simply copy and paste the string directly into the program and use it as a static variable.. But I was unable to actually open the .txt file, so I couldn’t copy and paste. My next attempt was to read the entire string from the file, but I can’t do this in a static method and it takes WAAAY too long (I actually don’t know exactly how long it takes, I closed the program eventually).
Is it possible to do this? Any help would be appreciated.
Edit: Potentially relevant information:
With this code:
/// <summary>
/// Gets a 500 million binary digit representation of Pi.
/// </summary>
public static string GetPi()
{
//as per http://msdn.microsoft.com/en-us/library/db5x7c0d.aspx
StreamReader piStream = new StreamReader(@"C:\binaryPi.txt");
string pi = "";
string line;
while ((line = piStream.ReadLine()) != null)
{
pi += line;
}
return pi;
}
I get an OutOfMemoryException.. So scanning the file actually doesn’t seem possible, unless I’m missing something..
so with the information available, i would just declare a bitarray (initial size as file.length) then i would open the file and reading it by chunk of maybe 4096 then you look trough these 4096 characters
in the loop you just do a simple if text = 1 then set true else set false
do this until you reach the end of the file then you have the full thing into a huge bitarray variable
from that point on you just need to find your pattern