On Tue, Jul 30, 2013 at 4:58 AM, Albert van der Horst
wrote:
> Notice that all values from i on are possibly present.
> So you are better off with a list indexed by forthcoming i's and
> each item containing a list of primes. What you do then, more or less,
> is keep track of all dividers of prime
Chris Angelico wrote:
> Bas wrote:
> > Still trying to figure out your algorithm ...
>
> It's pretty simple. (That's a bad start, I know!) Like the Sieve of
> Eratosthenes, it locates prime numbers, then deems every multiple of
> them to be composite. Unlike the classic sieve, it does the "deem"
>
In article ,
Chris Angelico wrote:
>And now for something completely different.
>
>I knocked together a prime number generator, just for the fun of it,
>that works like a Sieve of Eratosthenes but unbounded. It keeps track
>of all known primes and the "next composite" th
On 10 July 2013 19:56, Ian Kelly wrote:
> On Wed, Jul 10, 2013 at 11:47 AM, Joshua Landau wrote:
If you care about speed, you might want to check the heapq module.
Removing the smallest item and inserting a new item in a heap both cost
O(log(N)) time, while finding the minimum in
On Wed, Jul 10, 2013 at 11:47 AM, Joshua Landau wrote:
>>> If you care about speed, you might want to check the heapq module. Removing
>>> the smallest item and inserting a new item in a heap both cost O(log(N))
>>> time, while finding the minimum in a dictionary requires iterating over the
>>>
On 10 July 2013 17:15, Chris Angelico wrote:
> On Thu, Jul 11, 2013 at 1:47 AM, bas wrote:
>> On Wednesday, July 10, 2013 5:12:19 PM UTC+2, Chris Angelico wrote:
>>> Well, that does answer the question. Unfortunately the use of lambda
>>> there has a severe performance cost [ ...]
>> If you care
On Thu, Jul 11, 2013 at 2:54 AM, Ian Kelly wrote:
> As promised. Apologies for the excessive commenting. As noted, this
> implementation is a recursive generator, which is done so that the
> primes in the sieve can go only up to the square root of the current
> prime, rather than tossing in ever
On Wed, Jul 10, 2013 at 10:16 AM, Ian Kelly wrote:
> The other interesting thing about my sieve is that it's a recursive
> generator. I'll dig it up later and share it.
As promised. Apologies for the excessive commenting. As noted, this
implementation is a recursive generator, which is done so
On Thu, Jul 11, 2013 at 2:01 AM, Steven D'Aprano
wrote:
> On Thu, 11 Jul 2013 00:00:59 +1000, Chris Angelico wrote:
>> Thirdly, is there any sort of half-sane benchmark that I
>> can compare this code to? And finally, whose wheel did I reinvent here?
>> What name would this algorithm have?
>
> I c
On Thu, Jul 11, 2013 at 1:47 AM, bas wrote:
> On Wednesday, July 10, 2013 5:12:19 PM UTC+2, Chris Angelico wrote:
>> Well, that does answer the question. Unfortunately the use of lambda
>> there has a severe performance cost [ ...]
> If you care about speed, you might want to check the heapq modul
On Wed, Jul 10, 2013 at 8:00 AM, Chris Angelico wrote:
> And now for something completely different.
>
> I knocked together a prime number generator, just for the fun of it,
> that works like a Sieve of Eratosthenes but unbounded. It keeps track
> of all known primes and the "
On Thu, 11 Jul 2013 00:00:59 +1000, Chris Angelico wrote:
> And now for something completely different.
>
> I knocked together a prime number generator, just for the fun of it,
> that works like a Sieve of Eratosthenes but unbounded.
[...]
> So, a few questions. Firstly, is there
On Thu, Jul 11, 2013 at 1:43 AM, Joshua Landau wrote:
>> So, a few questions. Firstly, is there...
> Of course there is.
>
>> Secondly, can the...
> Of course it can.
>
>> Thirdly, is there...
> Of course there is. I have no clue what, though.
Heh, I guess I was asking for that kind of response :
On Wednesday, July 10, 2013 5:12:19 PM UTC+2, Chris Angelico wrote:
> Well, that does answer the question. Unfortunately the use of lambda
> there has a severe performance cost [ ...]
If you care about speed, you might want to check the heapq module. Removing the
smallest item and inserting a new
On 10 July 2013 15:00, Chris Angelico wrote:
> And now for something completely different.
>
> I knocked together a prime number generator, just for the fun of it,
> that works like a Sieve of Eratosthenes but unbounded. It keeps track
> of all known primes and the "next com
On Thu, Jul 11, 2013 at 12:35 AM, Bas wrote:
> On Wednesday, July 10, 2013 4:00:59 PM UTC+2, Chris Angelico wrote:
> [...]
>> So, a few questions. Firstly, is there a stdlib way to find the key
>> with the lowest corresponding value? In the above map, it would return
>> 3, because 18 is the lowest
On Wednesday, July 10, 2013 4:00:59 PM UTC+2, Chris Angelico wrote:
[...]
> So, a few questions. Firstly, is there a stdlib way to find the key
> with the lowest corresponding value? In the above map, it would return
> 3, because 18 is the lowest value in the list. I want to do this with
> a single
And now for something completely different.
I knocked together a prime number generator, just for the fun of it,
that works like a Sieve of Eratosthenes but unbounded. It keeps track
of all known primes and the "next composite" that it will produce -
for instance, after yielding 13, the
Thomas Jollans schrieb:
def primes():
yield 1
1 is not a prime number.
Greetings,
Thomas
--
Ce n'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!
(Coluche)
--
http://mail.python.org/mailman/listinfo/python-list
On 6/29/2010 12:51 PM, Thomas Jollans wrote:
def rprimes():
def elim_mult(n):
yield n
for p in filter((lambda x:x%n != 0), elim_mult(n+1)): yield p
yield 1
for p in elim_mult(2): yield p
Thomas, take a look at the thread "Generators/iterators, Pythonicity,
an
I've been toying with Haskell a bit, and after implementing
(essentially) the Sieve of Eratosthenes as an infinite list, thus:
primes = 1 : foldr elim_mult [] [2..]
where elim_mult n l = n : filter ((/=0) . (`mod` n)) l
I wondered how easy it would be to do the same thing in Python.
Obviously
21 matches
Mail list logo