Re: [gentoo-dev] [PATCH] qmail.eclass: simplify is_prime()

2021-06-18 Thread Rolf Eike Beer
Am Freitag, 18. Juni 2021, 21:10:27 CEST schrieb Michael Orlitzky: > > This depends on the actual domain of numbers. If the primes involved > > have 20 digits as in your example, then factor should be used of course. > > > > I suspect though that we're talking about small numbers (below 100?) > >

Re: [gentoo-dev] [PATCH] qmail.eclass: simplify is_prime()

2021-06-18 Thread Michael Orlitzky
> > This depends on the actual domain of numbers. If the primes involved > have 20 digits as in your example, then factor should be used of course. > > I suspect though that we're talking about small numbers (below 100?) > here, in which case a solution in pure bash would be preferable. > If

Re: [gentoo-dev] [PATCH] qmail.eclass: simplify is_prime()

2021-06-18 Thread Ulrich Mueller
> On Thu, 17 Jun 2021, Guilherme Amadio wrote: > There's actually a much simpler solution to this: > $ is_prime() { test $(factor $1 | cut -d: -f2 | wc -w) == 1; } > $ for n in $(seq 0 10); do is_prime $n && echo $n is prime; done > 2 is prime > 3 is prime > 5 is prime > 7 is prime > $ time

Re: [gentoo-dev] [PATCH] qmail.eclass: simplify is_prime()

2021-06-17 Thread Guilherme Amadio
Hi, On Thu, Jun 17, 2021 at 05:42:12PM +, Peter Stuge wrote: > Rolf Eike Beer wrote: > > The previous algorithm would scan for all primes for a given number, > > which takes needlessly long. > > Please also mention how this caused a problem for you in the commit > message, to help us

Re: [gentoo-dev] [PATCH] qmail.eclass: simplify is_prime()

2021-06-17 Thread Peter Stuge
Rolf Eike Beer wrote: > The previous algorithm would scan for all primes for a given number, > which takes needlessly long. Please also mention how this caused a problem for you in the commit message, to help us understand why you're proposing to change this. > +++ b/eclass/qmail.eclass > -#

[gentoo-dev] [PATCH] qmail.eclass: simplify is_prime()

2021-06-17 Thread Rolf Eike Beer
The previous algorithm would scan for all primes for a given number, which takes needlessly long. Signed-off-by: Rolf Eike Beer --- eclass/qmail.eclass | 45 - 1 file changed, 12 insertions(+), 33 deletions(-) diff --git a/eclass/qmail.eclass