On Feb 14, 5:26 am, [EMAIL PROTECTED] wrote:
> cokofree:
>
> > Sadly that is pretty slow though...
>
> It's quadratic, and it's not even short, you can do (quadratic still):
>
> print [x for x in range(2, 100) if all(x%i for i in range(2, x))]
>
> In D you can write similar code.
> Bye,
> bearophil
>
> > There's no finite state machine involved here, since this isn't a
> > regular expression in the strictest sense of the term---it doesn't
> > translate to a finite state machine, since backreferences are
> > involved.
> >
> > Mark
>
>
> What is it?
>
The language of strings of 1s whose lengt
cokofree:
> Sadly that is pretty slow though...
It's quadratic, and it's not even short, you can do (quadratic still):
print [x for x in range(2, 100) if all(x%i for i in range(2, x))]
In D you can write similar code.
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
> hmm... interesting
>
> here is another way you can find prime
> numbershttp://love-python.blogspot.com/2008/02/find-prime-number-upto-100-nu...
>
Sadly that is pretty slow though...
If you don't mind readability you can make the example I gave into
five lines.
def p(_):
if _<3:return[2]if _=
On Feb 13, 5:43 pm, Mark Dickinson <[EMAIL PROTECTED]> wrote:
> On Feb 13, 5:14 pm, [EMAIL PROTECTED] wrote:
>
> > Isn't the finite state machine "regular expression 'object'" really
> > large?
>
> There's no finite state machine involved here, since this isn't a
> regular expression in the stricte
On Feb 13, 5:14 pm, [EMAIL PROTECTED] wrote:
> Isn't the finite state machine "regular expression 'object'" really
> large?
There's no finite state machine involved here, since this isn't a
regular expression in the strictest sense of the term---it doesn't
translate to a finite state machine, sinc
On Feb 13, 9:48 am, Carsten Haese <[EMAIL PROTECTED]> wrote:
> On Wed, 2008-02-13 at 07:31 -0800, [EMAIL PROTECTED] wrote:
> > return re.match("^1?$|^(11+?)\1+$", convert)
>
> That needs to be either
>
> return re.match(r"^1?$|^(11+?)\1+$", convert)
>
> or
>
> return re.match("^1?$|^(11+?)\\1+$
hmm... interesting
here is another way you can find prime numbers
http://love-python.blogspot.com/2008/02/find-prime-number-upto-100-nums-range2.html
On Feb 13, 9:31 pm, [EMAIL PROTECTED] wrote:
> I was reading up on this site [http://www.noulakaz.net/weblog/
> 2007/03/18/a-regular-expression-t
On Feb 13, 12:53 pm, Carsten Haese <[EMAIL PROTECTED]> wrote:
> On Wed, 2008-02-13 at 10:40 -0800, [EMAIL PROTECTED] wrote:
> > But why doesn't it work when you make that change?
>
> I can't answer that question, because it *does* work when you make that
> change.
Well, the OP said the function wa
On Wed, 2008-02-13 at 10:40 -0800, [EMAIL PROTECTED] wrote:
> But why doesn't it work when you make that change?
I can't answer that question, because it *does* work when you make that
change.
--
Carsten Haese
http://informixdb.sourceforge.net
--
http://mail.python.org/mailman/listinfo/python
> -Original Message-
> From: [EMAIL PROTECTED] [mailto:python-
> [EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED]
> Sent: Wednesday, February 13, 2008 1:41 PM
> To: python-list@python.org
> Subject: Re: Regular Expression for Prime Numbers (or How I came to
> fail
On Feb 13, 9:48 am, Carsten Haese <[EMAIL PROTECTED]> wrote:
> On Wed, 2008-02-13 at 07:31 -0800, [EMAIL PROTECTED] wrote:
> > return re.match("^1?$|^(11+?)\1+$", convert)
>
> That needs to be either
>
> return re.match(r"^1?$|^(11+?)\1+$", convert)
>
> or
>
> return re.match("^1?$|^(11+?)\\1+$
with this works:
return re.match(r"^1?$|^(11+?)\1+$", convert)
but it match the non-prime numbers. So re_prime(2) will return null
and re_prime(4) will return a match
2008/2/13, Carsten Haese <[EMAIL PROTECTED]>:
> On Wed, 2008-02-13 at 07:31 -0800, [EMAIL PROTECTED] wrote:
> > return re.m
On Wed, 2008-02-13 at 07:31 -0800, [EMAIL PROTECTED] wrote:
> return re.match("^1?$|^(11+?)\1+$", convert)
That needs to be either
return re.match(r"^1?$|^(11+?)\1+$", convert)
or
return re.match("^1?$|^(11+?)\\1+$", convert)
in order to prevent "\1" from being read as "\x01".
--
Carsten
I was reading up on this site [http://www.noulakaz.net/weblog/
2007/03/18/a-regular-expression-to-check-for-prime-numbers/] of an
interesting way to work out prime numbers using Regular Expression.
However my attempts to use this in Python keep returning none
(obviously no match), however I don't
15 matches
Mail list logo