PI Phone Number Search Engine
This PI search engine is optimized for searching for seven digit strings (phone numbers) within PI.
Basically I downloaded the first 4.2 Billion digits of PI from here. With these I wrote several programs.
- unpack - takes a stream of encoded 2 digits per byte PI data and outputs a stream of normal ascii text with on digit per byte,
- index - takes a stream of ascii Pi and constructs a lookup table of the first occurence of every seven digit pattern in Pi. Basically it's just one giant array (10M elements) where the array index is the integer value of the seven digit sequence and the value is the position of it's first occurence (there is actually another array that keeps track of if the value has been found too). Once all possible seven digit combinations have been found (occurs within first 300M or so) the whole structure is written to disk in a binary file with 5 bytes per sequence. One byte is wether that number was found and the remaining four represent an unsigned long with the offset of that sequence.
- find - is the program for searching the binary file created by index. It basically takes a parameter of the seven digit sequence we are looking for, converts it to an integer, opens the datafile, and seeks to the offset of the sequence we are looking for. Then just reading in five bytes gives us our first occurence of that string. Really, really fast.
The source code for all this stuff (written in C) is available here. It's free to use for whatever and comes with a Makefile + first few hundred digits of PI for testing with.
The end result of this is a very fast way to find a seven digit sequence within PI. So have fun, search for your phone number or someone elses.