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


Groups > comp.lang.python > #101821

Re: Keen eyes

Path csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Subject Re: Keen eyes
Date Sun, 17 Jan 2016 09:30:26 +1100
Lines 20
Message-ID <mailman.47.1452983435.15297.python-list@python.org> (permalink)
References <d8e5eaf4-c59f-4635-8e73-f4a9a1a84877@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
X-Trace news.uni-berlin.de /CIl5MXS0TfTwJotYYdk8gdfrS4ArUn3Tt6nzhOkE2rw==
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.024
X-Spam-Evidence '*H*': 0.95; '*S*': 0.00; 'error:': 0.05; 'variable,': 0.07; 'cc:addr:python-list': 0.09; 'jan': 0.11; '2016': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'am,': 0.23; 'appears': 0.23; 'second': 0.24; 'header:In-Reply- To:1': 0.24; 'message-id:@mail.gmail.com': 0.27; 'function': 0.28; 'skip:s 30': 0.31; "who's": 0.32; 'point': 0.33; 'received:google.com': 0.35; 'received:209.85': 0.36; 'subject:: ': 0.37; 'received:209.85.213': 0.37; 'received:209': 0.38; 'someone': 0.38; 'your': 0.60; 'here.': 0.62; 'square': 0.76; "'prime'": 0.84; 'bite': 0.84; 'chrisa': 0.84; 'to:none': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=gsTkFNzD8r+Vt+XGFJwk72msKYfT57SH+APOc7ZFMqg=; b=TVbBEt5Zq9bm/m1hhO9HHyfWN+1SCVWKxUf2ANKeIdIfezUSn7DyZi/kSs1m9inlj6 FozPDT1zWKCCEtbe06cQpXYwdrmdwozCX/sn3xM3ZaU7pon1Jaz7WMNLjQC2J14ows3V W+kRIm0WtFNfUWE7CaUJP1Zz6JJUWorNPCb+nhil+3IHSlK2SehQUU0er80OjSeH48CQ uj77x/Zb7A+Dubg/RquDQyeWrID1ef20zjKxVHA7+FwFp5MWJNK6KZfej6VDvbUrquaq bd93unMUI6XLE57emxln64OuDDluBSJ/DoiN4ET/4z2kd0xbKRHw4SV54HBE0+lsjr0s i6zA==
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:cc:content-type; bh=gsTkFNzD8r+Vt+XGFJwk72msKYfT57SH+APOc7ZFMqg=; b=LL1OZ8SfUAG6aMsSsC18O2s6UN96TXQueSg7PaVtrmXZQ2tof0zydc5qAXZ3YbK+wX VCW9rsOc1rXJwarfa5BTsep4raYWNJUufgi3jbfYDhldgV95ngrfpmiZotb8EgQtiRer Z/k5cB2MBLmXbcbWHunilX8P5O1S5TxfFY1QGvR1OhuemtS0l2ohM+w7DZNtpJ4u/K18 Ln1fHSR3bpQBCMbWm35n0MrcyKYA6OZ9lEvQYo8DTGA2RSqsTFrVyVH0MXICMtxbYvvQ 4NZzgALvkfLFWtWCq3sY2eSy4XmPVmMyucBhbk0Ri/BQw2dHhdSxlEKextHfM63Jzsg5 2f8g==
X-Gm-Message-State AG10YOR3VWxcEO20usXHlRf28W4cy2Ed8JcjB8hN0tPQCQuQzM/hgwr1lZKOWH+5fhs9Ac0ym6Egpj4sm/2B8A==
X-Received by 10.50.111.169 with SMTP id ij9mr4878609igb.92.1452983426926; Sat, 16 Jan 2016 14:30:26 -0800 (PST)
In-Reply-To <d8e5eaf4-c59f-4635-8e73-f4a9a1a84877@googlegroups.com>
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>
Xref csiph.com comp.lang.python:101821

Show key headers only | View raw


On Sun, Jan 17, 2016 at 9:23 AM,  <jonas.thornvall@gmail.com> wrote:
> function factor_it(i){
> prime=true;
> sqroot=Math.floor(Math.sqrt(i));
> for (j=2;j<sqroot;j++){ k=i/j; prime=!Number.isInteger(k); if (prime) {return prime}}
> return prime;
> }

A couple of potential problems here. The first thing that comes to
mind is that floating point inaccuracy is going to bite you long
before the numbers "seem huge" to someone who's thinking about 2**53.
The second is an off-by-one error: a perfect square may come up as
prime.

Check for those and see how it looks.

Also, check your double-use of the 'prime' variable, which also
appears to be global here.

ChrisA

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


Thread

Keen eyes jonas.thornvall@gmail.com - 2016-01-16 14:23 -0800
  Re: Keen eyes Chris Angelico <rosuav@gmail.com> - 2016-01-17 09:30 +1100
    Re: Keen eyes jonas.thornvall@gmail.com - 2016-01-16 14:55 -0800
    Re: Keen eyes jonas.thornvall@gmail.com - 2016-01-16 15:25 -0800
      Re: Keen eyes Steven D'Aprano <steve@pearwood.info> - 2016-01-17 18:10 +1100
        Re: Keen eyes Ian Kelly <ian.g.kelly@gmail.com> - 2016-01-17 00:37 -0700
        Re: Keen eyes Paul Rubin <no.email@nospam.invalid> - 2016-01-16 23:52 -0800
        Re: Keen eyes Chris Angelico <rosuav@gmail.com> - 2016-01-17 19:25 +1100
          Re: Keen eyes BartC <bc@freeuk.com> - 2016-01-17 11:17 +0000
            Re: Keen eyes Chris Angelico <rosuav@gmail.com> - 2016-01-17 22:32 +1100

csiph-web