GithubHelp home page GithubHelp logo

dijkstraprimes's Introduction

dijkstraprimes's People

Contributors

heinrichhartmann avatar iblech avatar porocyon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

dijkstraprimes's Issues

small code improvement

Hi,

I was trying to understand this algorithm and implement it in python. In the process I have to propose

  • a small code improvement where the code part
  while #P < N do
    repeat
      x = x + 2
      if x >= limit then
        Q[#Q+1], limit = limit, P[#Q+2]^2
      end
    until is_prime(x)
    P[#P+1] = x
  end

can be replaced by just

  while #P < N do
    x = x + 2
    if x >= limit then
      Q[#Q+1], limit = limit, P[#Q+2]^2
    end
    if is_prime(x) then
      P[#P+1] = x
    end
  end

which eliminates one extra needless loop and is easier to understand

  • the blog statement
    "The largest prime we need to check is the one before the limit prime q, with index P[q_idx-1]. Q only stores values up to that index"
    is not so helpful and should be changed to the following or similar
The largest prime we need to check is the one before the limit prime q
whose square is kept in 'limit' variable
and entered as last entry in table Q when the 'limit' is exceeded
(because only then will this last Q entry have to be considered in the is_prime logic
and then this entry is updated as necessary again by the is_prime logic)
so table Q has always one less entry than table P
by the time table Q has to be extended by one entry it is certain that
table P will have already been extended too by the next prime

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.