GithubHelp home page GithubHelp logo

pinkdiamond1 / pi-scanner Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nat-n/pi-scanner

1.0 1.0 0.0 336 KB

A nodejs app to index and quickly scan billions of digits of pi for arbitrary sequences

Home Page: http://piscanner.natn.io/

JavaScript 50.43% Ruby 12.10% CoffeeScript 6.84% CSS 30.63%

pi-scanner's Introduction

PiScanner

A nodejs app for finding arbitrary sequences of decimal digits in Pi. Demo

Why?

For the sake of building something with nodejs, and um... ฯ€ is cool?

Installation requirements

Usage

To build an index, download as many digits as you want from the above link. Digits are available in zipped text files of 100 million each. Place a set of consecutive files (starting form pi-0001.txt) in within a subdirectory within of the project directory. Invoke the command line interface with no arguments to get, or like so to build the indexes in a default setup from within the project directory:

$ ./cli.js index
Indexed 10 input files in 291.182 seconds.
Wrote out 1000000000 digits in 291.172 seconds.

Querying the indexes with the CLI to locate a given sequence within pi:

$ ./cli.js scan 1999
Scanning indexes for sequence 1999
Found sequence "1999" in pi, starting after 11195 decimal places, in 0.033 seconds.

Querying the indexes with the CLI to retrieve a range of digits from pi:

$ ./cli.js range 11190:11200
1290019992

Launching the web service:

$ ./app.js

Under the hood

Searching for sequences in Pi is a difficult problem because it's essentially an endless string of random numbers, allowing for very few optimising assumptions. However you go about it, the result is basically an enhanced linear search, where extra efficiency requires ever larger indexes.

The present approach was to create an index for each distinct digit ('0' through '9'), in the form of a binary file of 8 bit integers. The first number in each index indicates the decimal place of the first occurrence of that digit. The second number indicates the number of decimal places further along of the next occurrence of that digit, and so on. Thus location of the nth a given digit can be found by summing the first n values in the corresponding index file.

These ten indexes could be enough to allow for sequences to be found by walking each index in parallel until a match is found. However for the sake of speed and simplicity a digits file is also used, which consists the entire string of digits, packed with 4 bits per digit. Thus the digit index files are used to quickly locate potential matches based on the first digit of the query, and an attempt is then made to match the rest of the query with the corresponding digits from the digits file.

Typical performance

Indexing one billion digits takes just under 5 minutes with an SSD, whereas the resulting index takes about 7 seconds to scan entirely.

pi-scanner's People

Contributors

nat-n avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.