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


Groups > comp.lang.python > #89740

Re: Is my implementation of happy number OK

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.067
X-Spam-Evidence '*H*': 0.87; '*S*': 0.00; 'subject:number': 0.09; 'python': 0.11; 'def': 0.12; 'random': 0.14; 'subject:happy': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; "doesn't": 0.30; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'url:wiki': 0.31; "d'aprano": 0.31; 'steven': 0.31; 'subject:skip:i 10': 0.31; 'url:wikipedia': 0.31; 'computer.': 0.33; 'fri,': 0.33; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'sequence': 0.36; 'url:org': 0.36; 'example,': 0.37; 'to:addr:python-list': 0.38; 'rather': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; 'most': 0.60; '500': 0.70; 'square': 0.74; '2015': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=kE1ye8Tl+YZqf4gnUSi6y+JX3SoD7TmuL0myXTwHgp8=; b=vmpr0nSUBuGzylaCfdn9BZ63cVa/mNCwLAMQ+uhc9gYvjTZL3c0AepR1+IpgcQjW3N 7HR89rEMfuvOrnl0VJnCZZb+B5xi6JZxt9DLlL7xXhoAy8iqvv/rkHKV8WXaNzt+xPRT I2zeZVifMbHw55AbJeRbjWYk5NfT65btwBa7mRyT+F2FejzSN6PkQj76Jm29D5nFNZVw xg+KjB7nWISjzzlAuCp70l5QEnVfGiGgFiGVjNRLtZ9/6hHExgZAPyPcyb3VU0bTIGii u3738sAw/EkpmQmq1f1DVPEYTAsaDjEm4Z1e4pnlGpiKJ3PesvowbuSiDXtsMFtZp7YQ lAEw==
X-Received by 10.107.17.29 with SMTP id z29mr12891069ioi.69.1430492652477; Fri, 01 May 2015 08:04:12 -0700 (PDT)
MIME-Version 1.0
In-Reply-To <554338dd$0$13004$c3e8da3$5496439d@news.astraweb.com>
References <87oam5vc8k.fsf@Equus.decebal.nl> <mailman.140.1430420006.3680.python-list@python.org> <slrnmk5esv.apd.jon+usenet@frosty.unequivocal.co.uk> <mailman.155.1430437953.3680.python-list@python.org> <slrnmk6agn.apd.jon+usenet@frosty.unequivocal.co.uk> <554338dd$0$13004$c3e8da3$5496439d@news.astraweb.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Fri, 1 May 2015 09:03:32 -0600
Subject Re: Is my implementation of happy number OK
To Python <python-list@python.org>
Content-Type text/plain; charset=UTF-8
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.18.1430492660.3347.python-list@python.org> (permalink)
Lines 20
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1430492660 news.xs4all.nl 2905 [2001:888:2000:d::a6]:59301
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:89740

Show key headers only | View raw


On Fri, May 1, 2015 at 2:27 AM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
> Rather than 10**7, how about trying (10**500 + 2). Is it happy?
>
> Using the Python code from Wikipedia:
> https://en.wikipedia.org/wiki/Happy_number
>
> SQUARE = dict([(c, int(c)**2) for c in "0123456789"])
> def is_happy(n):
>   while (n > 1) and (n != 4):
>     n = sum(SQUARE[d] for d in str(n))
>   return n == 1
>
>
> I can calculate whether n=10**500 + 2 is happy in less than a millisecond on
> my computer.

Not really the most exciting example, since the following number in
the sequence would be 5. But a random sequence of 500 non-zero digits
doesn't seem to take substantially longer.

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