On 25-10-12 16:47, Charles Hixson wrote:
In Python3 is there any good way to count the number of on bits in an
integer (after an operation)?
Alternatively, is there any VERY light-weight implementation of a bit
set? I'd prefer to use integers, as I'm probably going to need
thousands of
On 2012-10-25, Ian Kelly ian.g.ke...@gmail.com wrote:
On Thu, Oct 25, 2012 at 2:00 PM, Neil Cerutti
ne...@norwich.edu wrote:
Yes indeed! Python string operations are fast enough and its
arithmetic slow enough that I no longer assume I can beat a
neat lexicographical solution. Try defeating
On Thursday, October 25, 2012 7:56:25 AM UTC-7, Charles Hixson wrote:
In Python3 is there any good way to count the number of on bits in an
integer (after an operation)?
You may want to look at gmpy2[1] and the popcount() function.
Alternatively, is there any VERY light-weight
cas...@gmail.com wrote:
On Thursday, October 25, 2012 7:56:25 AM UTC-7, Charles Hixson wrote:
In Python3 is there any good way to count the number of on bits in an
integer (after an operation)?
You may want to look at gmpy2[1] and the popcount() function.
Alternatively, is there any VERY
In Python3 is there any good way to count the number of on bits in an
integer (after an operation)?
Alternatively, is there any VERY light-weight implementation of a bit
set? I'd prefer to use integers, as I'm probably going to need
thousands of these, if the tests work out. But before I can
On 2012-10-25 15:47, Charles Hixson wrote:
In Python3 is there any good way to count the number of on bits in an
integer (after an operation)?
Alternatively, is there any VERY light-weight implementation of a bit
set? I'd prefer to use integers, as I'm probably going to need
thousands of
Am 25.10.2012 16:47, schrieb Charles Hixson:
In Python3 is there any good way to count the number of on bits in an
integer (after an operation)?
Simple, easy, faster than a Python loop but not very elegant:
bin(number).count(1)
Christian
--
On Fri, Oct 26, 2012 at 2:25 AM, Christian Heimes christ...@python.org wrote:
Simple, easy, faster than a Python loop but not very elegant:
bin(number).count(1)
Unlikely to be fast.
What you may want is some sort of hybrid loop/lookup approach. Do you
know what your highest bit number is
On Fri, 26 Oct 2012 02:31:53 +1100, Chris Angelico wrote:
On Fri, Oct 26, 2012 at 2:25 AM, Christian Heimes christ...@python.org
wrote:
Simple, easy, faster than a Python loop but not very elegant:
bin(number).count(1)
Unlikely to be fast.
Oh I don't know about that. Here's some
On Oct 25, 7:56 pm, Charles Hixson charleshi...@earthlink.net wrote:
In Python3 is there any good way to count the number of on bits in an
integer (after an operation)?
Alternatively, is there any VERY light-weight implementation of a bit
set? I'd prefer to use integers, as I'm probably
On Oct 25, 8:57 pm, Steven D'Aprano steve
+comp.lang.pyt...@pearwood.info wrote:
On Fri, 26 Oct 2012 02:31:53 +1100, Chris Angelico wrote:
On Fri, Oct 26, 2012 at 2:25 AM, Christian Heimes christ...@python.org
wrote:
Simple, easy, faster than a Python loop but not very elegant:
On 25/10/2012 15:47, Charles Hixson wrote:
In Python3 is there any good way to count the number of on bits in an
integer (after an operation)?
Alternatively, is there any VERY light-weight implementation of a bit
set? I'd prefer to use integers, as I'm probably going to need
thousands of
On Fri, Oct 26, 2012 at 3:17 AM, rusi rustompm...@gmail.com wrote:
On Oct 25, 8:57 pm, Steven D'Aprano steve
+comp.lang.pyt...@pearwood.info wrote:
py min(t.repeat(number=1, repeat=7))
0.6819710731506348
py min(t.repeat(number=100, repeat=7))
4.141788959503174
That makes the inelegant
On Thu, Oct 25, 2012 at 9:24 AM, Mark Lawrence breamore...@yahoo.co.ukwrote:
On 25/10/2012 15:47, Charles Hixson wrote:
In Python3 is there any good way to count the number of on bits in an
integer (after an operation)?
Alternatively, is there any VERY light-weight implementation of a bit
On 25/10/2012 17:29, Chris Angelico wrote:
On Fri, Oct 26, 2012 at 3:17 AM, rusi rustompm...@gmail.com wrote:
On Oct 25, 8:57 pm, Steven D'Aprano steve
+comp.lang.pyt...@pearwood.info wrote:
py min(t.repeat(number=1, repeat=7))
0.6819710731506348
py min(t.repeat(number=100, repeat=7))
On Oct 25, 9:30 pm, Chris Angelico ros...@gmail.com wrote:
On Fri, Oct 26, 2012 at 3:17 AM, rusi rustompm...@gmail.com wrote:
On Oct 25, 8:57 pm, Steven D'Aprano steve
+comp.lang.pyt...@pearwood.info wrote:
py min(t.repeat(number=1, repeat=7))
0.6819710731506348
py
On Thu, 25 Oct 2012 09:17:40 -0700, rusi wrote:
On Oct 25, 8:57 pm, Steven D'Aprano steve
+comp.lang.pyt...@pearwood.info wrote:
On Fri, 26 Oct 2012 02:31:53 +1100, Chris Angelico wrote:
On Fri, Oct 26, 2012 at 2:25 AM, Christian Heimes
christ...@python.org wrote:
Simple, easy, faster
Am 25.10.12 16:47, schrieb Charles Hixson:
In Python3 is there any good way to count the number of on bits in an
integer (after an operation)?
Alternatively, is there any VERY light-weight implementation of a bit
set? I'd prefer to use integers, as I'm probably going to need
thousands of
On Thu, Oct 25, 2012 at 11:25 AM, Christian Gollwitzer aurio...@gmx.de wrote:
There is a very geeky algorithm with only a few integer operations.
Checkout
http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSet64
for a C version. Maybe the same thing is equally fast when ported to
Chris Angelico's suggestion:
bitcount = bytes(bin(i).count(1) for i in range(256))
t = Timer('sum(number.to_bytes((number.bit_length() + 7) // 8,'
... 'little).translate(bitcount))',
... setup='from __main__ import bitcount; number=2**10001-1')
min(t.repeat(number=1, repeat=7))
--
On 2012-10-25, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote:
On Fri, 26 Oct 2012 02:31:53 +1100, Chris Angelico wrote:
On Fri, Oct 26, 2012 at 2:25 AM, Christian Heimes
christ...@python.org
wrote:
Simple, easy, faster than a Python loop but not very elegant:
On 2012-10-25, Neil Cerutti ne...@norwich.edu wrote:
Try defeating the following with arithmetic:
def is_palindrom(n):
s = str(n)
return s = s[::-1]
Sorry for the typos. It should've been:
def is_palindrome(n):
s = str(n)
return s == s[::-1]
--
Neil Cerutti
--
On 10/25/2012 12:13 PM, rusi wrote:
On Oct 25, 7:56 pm, Charles Hixson charleshi...@earthlink.net wrote:
In Python3 is there any good way to count the number of on bits in an
integer (after an operation)?
Alternatively, is there any VERY light-weight implementation of a bit
set? I'd prefer to
On Thu, Oct 25, 2012 at 2:00 PM, Neil Cerutti ne...@norwich.edu wrote:
Yes indeed! Python string operations are fast enough and its
arithmetic slow enough that I no longer assume I can beat a neat
lexicographical solution. Try defeating the following with
arithmetic:
def is_palindrom(n):
In Python3 is there any good way to count the number of on bits in an
integer (after an operation)?
Alternatively, is there any VERY light-weight implementation of a bit
set? I'd prefer to use integers, as I'm probably going to need
thousands of these, if the tests work out. But before I can
On 10/25/2012 08:57 AM, Steven D'Aprano wrote:
On Fri, 26 Oct 2012 02:31:53 +1100, Chris Angelico wrote:
On Fri, Oct 26, 2012 at 2:25 AM, Christian Heimeschrist...@python.org
wrote:
Simple, easy, faster than a Python loop but not very elegant:
bin(number).count(1)
Unlikely to be fast.
In Python3 is there any good way to count the number of on bits in an
integer (after an operation)?
Alternatively, is there any VERY light-weight implementation of a bit
set? I'd prefer to use integers, as I'm probably going to need
thousands of these, if the tests work out. But before I can
On 25/10/2012 17:08, Charles Hixson wrote:
On 10/25/2012 08:57 AM, Steven D'Aprano wrote:
On Fri, 26 Oct 2012 02:31:53 +1100, Chris Angelico wrote:
On Fri, Oct 26, 2012 at 2:25 AM, Christian Heimeschrist...@python.org
wrote:
Simple, easy, faster than a Python loop but not very elegant:
On Thu, 25 Oct 2012 14:20:00 -0600, Ian Kelly wrote:
On Thu, Oct 25, 2012 at 2:00 PM, Neil Cerutti ne...@norwich.edu wrote:
Yes indeed! Python string operations are fast enough and its arithmetic
slow enough that I no longer assume I can beat a neat lexicographical
solution. Try defeating the
29 matches
Mail list logo