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" that it will produce -
>for
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 "next composite" that
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 a stdlib way to
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 composite" that it will pr
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
In article <[EMAIL PROTECTED]>,
lostinpython <[EMAIL PROTECTED]> wrote:
>It is a homework assignment from a book but not for a class. I'm
>trying to teach my self some basic programming before I have to take it
>in college. If I show enough understanding of the subject, my advisor
>will let me fo
lostinpython wrote:
> What civil engineers need with all this programming is beyond me. We
> have to learn another language to program our CADD software, which I
> find much easier than this.
According to my experience, almost every engineer - civil or not - uses
programming at least occationa
Sigh ... one of my intermediate versions of is_prime() returns True if
the n is *not* prime, and false otherwise. The final version is
correct, though.
Dale.
--
http://mail.python.org/mailman/listinfo/python-list
lostinpython> I'm having trouble writing a program that figures
lostinpython> out a prime number. Does anyone have an idea on how
lostinpython> to write it?
[I can't quite tell from your posts what your level of programming
knowledge is, so I've aimed low. If this was wrong, please
lostinpython wrote:
> But needless to say, I'm stumped on this
> problem. I keep ending up in a never ending loop.
I've been told that the trick with recursion/iteration is to always
determine what your ending condition is first, and then construct the
body of the recursion/loop to reach that e
> What civil engineers need with all this programming is beyond me.
One of my best friends and expartner and top civil-structural
engineers in the country (he built Dallas Reunion Arena and many
other complex structures) was an ace programmer in many languages.
He was not willing to just accep
lostinpython said unto the world upon 2005-05-30 02:50:
> It is a homework assignment from a book but not for a class. I'm
> trying to teach my self some basic programming before I have to take it
> in college. If I show enough understanding of the subject, my advisor
> will let me forgo Intro. t
It is a homework assignment from a book but not for a class. I'm
trying to teach my self some basic programming before I have to take it
in college. If I show enough understanding of the subject, my advisor
will let me forgo Intro. to Programming and go into Intro. to C++.
What civil engineers ne
"lostinpython" <[EMAIL PROTECTED]> writes:
> I'm having trouble writing a program that figures out a prime number.
> Does anyone have an idea on how to write it? All I know is that n > 2
> is prim if no number between 2 and sqrt of n (inclusivly) evenly
> divides n.
How about this (untested):
im
On 29 May 2005 19:55:32 -0700, lostinpython
<[EMAIL PROTECTED]> wrote:
> I'm having trouble writing a program that figures out a prime number.
> Does anyone have an idea on how to write it? All I know is that n > 2
> is prim if no number between 2 and sqrt of n (inclusivly) evenly
> divides n.
Th
27 matches
Mail list logo