Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #89686

Re: Is my implementation of happy number OK

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <davea@davea.name>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.174
X-Spam-Level *
X-Spam-Evidence '*H*': 0.66; '*S*': 0.01; 'memory.': 0.07; 'subject:number': 0.09; 'python': 0.11; 'complaining': 0.16; 'fetch': 0.16; 'happy.': 0.16; 'output?': 0.16; 'set,': 0.16; 'sooner.': 0.16; 'subject:happy': 0.16; 'wrote:': 0.18; 'all,': 0.19; 'producing': 0.19; 'version.': 0.19; 'memory': 0.22; 'header :User-Agent:1': 0.23; 'finally,': 0.24; 'space.': 0.24; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'testing': 0.29; 'subject:skip:i 10': 0.31; 'values.': 0.31; 'could': 0.34; 'problem': 0.35; 'problem.': 0.35; 'but': 0.35; 'version': 0.36; "didn't": 0.36; 'example,': 0.37; 'members.': 0.37; 'wrong': 0.37; 'list': 0.37; 'mine': 0.38; 'solving': 0.38; 'to:addr:python- list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'even': 0.60; 'dave': 0.60; "you're": 0.61; 'times': 0.62; 'real': 0.63; 'different': 0.65; 'charset:windows-1252': 0.65; 'determine': 0.67; 'six': 0.68; 'received:74.208': 0.68; 'results': 0.69; 'limit': 0.70; 'savings': 0.81; 'actually,': 0.84; 'criticism;': 0.84; 'sets,': 0.84; 'yours': 0.88; '(running': 0.91; 'angel': 0.91; 'items,': 0.91
Date Thu, 30 Apr 2015 19:52:13 -0400
From Dave Angel <davea@davea.name>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0
MIME-Version 1.0
To python-list@python.org
Subject Re: Is my implementation of happy number OK
References <87oam5vc8k.fsf@Equus.decebal.nl> <mailman.140.1430420006.3680.python-list@python.org> <slrnmk5esv.apd.jon+usenet@frosty.unequivocal.co.uk>
In-Reply-To <slrnmk5esv.apd.jon+usenet@frosty.unequivocal.co.uk>
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 7bit
X-Provags-ID V03:K0:77Y/JJbjiwt6ayDV0jq8EbUcxcTNvYaYOn+coXYLQ7i+o25pibf bp60HQCgsooR3DrsMW482kTTqiIuwQN/e3g+4j2FF+fAwXCWDu6SI9A21wJENdynUvXzsef 4Cwq8Nyjm1vHvK+LjzaprqLashVeFpRLtt83mSgUQePMiRNT1gCQTjVinLwBqLOJZp13DUq y4a4sL+mD8tqEx3Zo9gZA==
X-UI-Out-Filterresults notjunk:1;
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.155.1430437953.3680.python-list@python.org> (permalink)
Lines 35
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1430437953 news.xs4all.nl 2856 [2001:888:2000:d::a6]:46641
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:89686

Show key headers only | View raw


On 04/30/2015 07:31 PM, Jon Ribbens wrote:
> On 2015-04-30, Dave Angel <davea@davea.name> wrote:
>> Finally, I did some testing on Jon Ribben's version.  His was
>> substantially faster for smaller sets, and about the same for 10*7.  So
>> it's likely it'll be slower than yours and mine for 10**8.
>
> You know what they say about assumptions. Actually, my version is six
> times faster for 10**8 (running under Python 3.4).
>
>> But the real reason I didn't like it was it produced a much larger
>> set of happy_numbers, which could clog memory a lot sooner.  For
>> 10**7 items, I had 3250 happy members, and 19630 unhappy.  And Jon
>> had 1418854 happy members.
>
> Er, what? You're complaining that mine is less efficient by not
> producing the wrong output?
>

It's not intended as a criticism;  you solved a different problem.  The 
problem Cecil was solving was to determine if a particular number is 
happy.  The problem you solved was to make a list of all values under a 
particular limit that are happy.

Both produce identical results for the Cecil purpose, and yours is 
faster if one wants all the values.  But if one wants a sampling of 
values, his function will fetch them quickly, and even if you want them 
all, his function will use much less memory.

He keeps only one permutation of each value in the set, for substantial 
savings in space.  For example, he might just keep 28, while you keep 28 
and 82, 208, 280, 802, and 820.


-- 
DaveA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Is my implementation of happy number OK Cecil Westerhof <Cecil@decebal.nl> - 2015-04-30 17:59 +0200
  Re: Is my implementation of happy number OK Jon Ribbens <jon+usenet@unequivocal.co.uk> - 2015-04-30 17:04 +0000
  Re: Is my implementation of happy number OK Ian Kelly <ian.g.kelly@gmail.com> - 2015-04-30 11:37 -0600
    Re: Is my implementation of happy number OK Cecil Westerhof <Cecil@decebal.nl> - 2015-04-30 21:05 +0200
  Re: Is my implementation of happy number OK Dave Angel <davea@davea.name> - 2015-04-30 14:53 -0400
    Re: Is my implementation of happy number OK Cecil Westerhof <Cecil@decebal.nl> - 2015-04-30 22:35 +0200
      Re: Is my implementation of happy number OK Dave Angel <davea@davea.name> - 2015-04-30 17:31 -0400
    Re: Is my implementation of happy number OK Jon Ribbens <jon+usenet@unequivocal.co.uk> - 2015-04-30 23:31 +0000
      Re: Is my implementation of happy number OK Dave Angel <davea@davea.name> - 2015-04-30 19:52 -0400
        Re: Is my implementation of happy number OK Cecil Westerhof <Cecil@decebal.nl> - 2015-05-01 06:36 +0200
        Re: Is my implementation of happy number OK Jon Ribbens <jon+usenet@unequivocal.co.uk> - 2015-05-01 07:23 +0000
          Re: Is my implementation of happy number OK Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-01 18:27 +1000
            Re: Is my implementation of happy number OK Ian Kelly <ian.g.kelly@gmail.com> - 2015-05-01 09:03 -0600
            Re: Is my implementation of happy number OK Peter Otten <__peter__@web.de> - 2015-05-01 20:13 +0200
              Re: Is my implementation of happy number OK Jon Ribbens <jon+usenet@unequivocal.co.uk> - 2015-05-02 21:23 +0000

csiph-web