Git Product home page Git Product logo

ulam-spiral's Introduction

Ulam Spiral ꩜

C++ unit badge

This program generates an ulam spiral and saves it to a *.ppm image file. I've used the sieve of Eratosthenes to find all primes under a max value which is calculated from the width of the out-image.

example output converted to png

Ulam spiral πŸ‡΅πŸ‡±

Ulam spiral is a graphical way of presenting the set of prime numbers. It was firstly described by a brilliant polish mathematician StanisΕ‚aw Ulam. In order to construct ulam spiral one has to:

  • write down positive integers in a shape of a square spiral
  • and then mark all prime numbers

Ulam spiral shows an interesting pattern in the distribution on primes. Notice the clearly visible horizontal and diagonal lines.

Construction of an ulam spiral (source Wikipedia):

Ulam Spiral image 1 Ulam Spiral image 2

Sieve of Eratosthenes πŸ‡¬πŸ‡·

This is a simple algorithm that allows to find all prime numbers up to a specified max value.

The algorithm iteratively marks every composite number (this is a number that is not prime πŸ’β€β™‚οΈ) by calculating multiples of prime numbers. It starts from the first prime number (2).

Further reading πŸ”Ž


Build πŸ”§

$ cd build/
$ cmake .. -DCMAKE_BUILD_TYPE=Debug -G "Unix Makefiles"
$ make all
$ ./bin/ulam-spiral

Running tests

I'm using googletest release-1.10.0. It is added as a git submodule. In order to run tests, you have to checkout this repo with submodules. You can do it with:

$ git submodule update --init --recursive

Alternatively, you can download all submodules during cloning:

$ git clone --recursive git://github.com/pniewiejski/luhnjs.git
$ cd build/
$ cmake .. -DCMAKE_BUILD_TYPE=Debug -G "Unix Makefiles"
$ make all
$ ./bin/ulam-spiral_test

Code style ✍️

Code formatting was done using clang-format. I've created a simple bash script (format-code.sh) that runs the clang-format command. clang-format config was generated using:

$ clang-format -style=google -dump-config > .clang-format

Image file format

I'm using Netpbm's portable bitmap format (P1) because there's hardly anything simpler than that 😜.

ulam-spiral's People

Contributors

pniewiejski avatar

Stargazers

 avatar  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.