Re: math - need divisors algorithm
- From: Joal Heagney <joal@xxxxxxxxxxxxxx>
- Date: Thu, 31 Mar 2005 12:29:36 GMT
Ed Suominen wrote:
Philp Smith wrote:
Hi
Does anyone have suggested code for a compact, efficient, elegant, most of all pythonic routine to produce a list of all the proper divisors of an integer (given a list of prime factors/powers)
Is this compact enough? :-)
def properDivisors(N): return [x for x in range(1,N-2) if not divmod(N,x)[1]]
--- Ed Suominen Registered Patent Agent Open-Source Software Author (yes, both...) Web Site: http://www.eepatents.com
I tried this out, (Python 2.3) and ran into the situation where neither xrange or range won't accept anything other than an int. (To quote the "bards", "53487861112345 is RIGHT out.") I was wondering how others would deal with this situation?
Joal .
- References:
- Re: math - need divisors algorithm
- From: Ed Suominen
- Re: math - need divisors algorithm
- Prev by Date: Re: LD_LIBRARY_PATH - how to set?
- Next by Date: Re: LD_LIBRARY_PATH - how to set?
- Previous by thread: Re: math - need divisors algorithm
- Next by thread: Re: math - need divisors algorithm
- Index(es):
Relevant Pages
|