Giter Site home page Giter Site logo

prime-tester's Introduction

prime-tester

A Python program for doing things with prime numbers.

Launching the program grants you with a selection menu. Here, three options open to you :

  • Check if a number is prime
  • Display every prime number up to a given number
  • Benchmark your system with prime numbers

Prime checking

Checking if a number is prime is done efficiently by three functions:

  • isDivisibleByThree() checks the last digit of the number. If that digit is 0, 2, 4, 5, 6 or 8, then the number can't be prime because it can be at least divided by 2 or 5.
  • isDivisibleByThree() checks the digital root of the number (sum of all digits). If the digital root of a number is divisible by three, then the number is divisible by three. For example, digital root of 123 is 1+2+3=6, 6 is divisible by 3, so 123 is divisible by three. It's a modular arithmetic trick, I remember seeing a demonstration for it in math courses, I have to find it again.
  • isDivisibleByMoreThanSeven() searches for dividers equal or higher than 7. This function checks every non-previously tested number up to the square root of the number we are checking.

Benchmark

You are able to benchmark your system with primes numbers. The program searches for primes up to a given limit and records time taken by the operation.

Improvements to be made:

  • Algorithm has most likely room for improvements. It's already pretty optimized but I'm sure we can find primes faster ;)
  • Benchmark has to be adjusted to fit a real-world usecase. Calculating too few primes doesn't provide an accurate measure with modern computers, and calculating too many can take more time than the universe's age...
  • I would like to implement an option for choosing between single-threading and multi-threading. This program appears to take all threads by default. I have to learn how to handle threads, because it's now out of my reach.

prime-tester's People

Contributors

mario-moreau 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.