Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #32215
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail |
|---|---|
| From | Neil Cerutti <neilc@norwich.edu> |
| Newsgroups | comp.lang.python |
| Subject | Re: bit count or bit set && Python3 |
| Date | 26 Oct 2012 12:56:27 GMT |
| Organization | Norwich University |
| Lines | 26 |
| Message-ID | <aevfjqFaa5tU3@mid.individual.net> (permalink) |
| References | <5089511E.4090009@earthlink.net> <k6bllq$3gt$1@ger.gmane.org> <mailman.2849.1351179123.27098.python-list@python.org> <50896152$0$29978$c3e8da3$5496439d@news.astraweb.com> <aetk2pFsd2rU3@mid.individual.net> <mailman.2864.1351196432.27098.python-list@python.org> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| Content-Transfer-Encoding | 7bit |
| X-Trace | individual.net MSErZRZ1toFZ8Ook1lQuPAtHc8jQ03Zyg8j6DP5J0esuYAwfCd4wfmQzulrhlxmm/f |
| Cancel-Lock | sha1:SX7N+WgVax0/u0Uoff8Nx8l9wFU= |
| User-Agent | slrn/0.9.9p1/mm/ao (Win32) |
| Xref | csiph.com comp.lang.python:32215 |
Show key headers only | View raw
On 2012-10-25, Ian Kelly <ian.g.kelly@gmail.com> wrote: > On Thu, Oct 25, 2012 at 2:00 PM, Neil Cerutti > <neilc@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): >> s = str(n) >> return s = s[::-1] > > Problems like these are fundamentally string problems, not math > problems. The question being asked isn't about some essential > property of the number, but about its digital representation. > Certainly they can be reasoned about mathematically, but the > fact remains that the math being done is about the properties > of strings. The "unexpected" part, to me, is that an optimal arithmetic based solution conceptually is more efficient. You need to compute just half the digits of the number and then perform a contant compare operation. -- Neil Cerutti
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: bit count or bit set && Python3 Chris Angelico <rosuav@gmail.com> - 2012-10-26 02:31 +1100
Re: bit count or bit set && Python3 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-10-25 15:57 +0000
Re: bit count or bit set && Python3 rusi <rustompmody@gmail.com> - 2012-10-25 09:17 -0700
Re: bit count or bit set && Python3 Chris Angelico <rosuav@gmail.com> - 2012-10-26 03:29 +1100
Re: bit count or bit set && Python3 rusi <rustompmody@gmail.com> - 2012-10-25 09:37 -0700
Re: bit count or bit set && Python3 Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-10-25 17:44 +0100
Re: bit count or bit set && Python3 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-10-25 17:16 +0000
Re: bit count or bit set && Python3 Serhiy Storchaka <storchaka@gmail.com> - 2012-10-25 22:07 +0300
Re: bit count or bit set && Python3 Neil Cerutti <neilc@norwich.edu> - 2012-10-25 20:00 +0000
Re: bit count or bit set && Python3 Neil Cerutti <neilc@norwich.edu> - 2012-10-25 20:04 +0000
Re: bit count or bit set && Python3 Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-25 14:20 -0600
Re: bit count or bit set && Python3 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-10-25 23:48 +0000
Re: bit count or bit set && Python3 Neil Cerutti <neilc@norwich.edu> - 2012-10-26 12:56 +0000
Re: bit count or bit set && Python3 Charles Hixson <charleshixsn@earthlink.net> - 2012-10-25 09:08 -0700
Re: bit count or bit set && Python3 Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-10-25 22:51 +0100
csiph-web