Skip to content

How to generate primes in descending order? #235

Description

@anshwad10

I have a prime p, and I need to a list of all the primes upto it in descending order (the order is important for my situation). The obvious way to do this is to write [p, pred p ..] using the enum instance for primes, except that this sometimes does not do what one would expect; for example, if p = 7, this gives the list [7,5,3] instead of [7,5,3,2], It seems this is because the code sees that the two primes 7 and 5 are both 1 mod 2 and interprets this as asking for only the primes that are 1 mod 2. (Also, this "feature" that it will only generate primes with the same value mod their difference is really annoying in many cases when I dont want it, and i havent used it that much anyways.) The only way I see to do this is to generate the list of primes in ascending order, and then reverse it, which feels kind of wasteful, and there should be a more efficient way of generating primes in descending order IMO

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions