Path: csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: Keen eyes Date: Sun, 17 Jan 2016 09:30:26 +1100 Lines: 20 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de /CIl5MXS0TfTwJotYYdk8gdfrS4ArUn3Tt6nzhOkE2rw== Return-Path: 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: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:101821 On Sun, Jan 17, 2016 at 9:23 AM, wrote: > function factor_it(i){ > prime=true; > sqroot=Math.floor(Math.sqrt(i)); > for (j=2;j 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