Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #89676
| Date | 2015-04-30 17:31 -0400 |
|---|---|
| From | Dave Angel <davea@davea.name> |
| Subject | Re: Is my implementation of happy number OK |
| References | <87oam5vc8k.fsf@Equus.decebal.nl> <mailman.140.1430420006.3680.python-list@python.org> <87vbgds6b7.fsf@Equus.decebal.nl> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.148.1430429500.3680.python-list@python.org> (permalink) |
On 04/30/2015 04:35 PM, Cecil Westerhof wrote: > Op Thursday 30 Apr 2015 20:53 CEST schreef Dave Angel: > >> >> 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. 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. > > My version has 1625 and 9814. I do not understand the difference. > My error. I had also written a version of the function that stored strings instead of ints, and the counts of 3250/19630 was for sets that had BOTH. An exercise for the reader. Notice that in my brute force algorithm I use no global sets. But I do use an internal list, which is apparently unbounded. So it's feasible to run out of memory. The challenge is to write a similar function that uses no lists, sets, or dicts, just an algorithm that detects for an arbitrary sized number whether it's happy or not. (It may not be very quick, but that's yet to be decided. I'm already surprised that the present brute force function davea1() only takes about twice as long as the fancy global caching schemes. -- DaveA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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