Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.030 X-Spam-Evidence: '*H*': 0.94; '*S*': 0.00; 'say,': 0.05; 'cc:addr :python-list': 0.11; '(big': 0.16; 'ans': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'simplified': 0.16; 'subject:after': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'version.': 0.19; 'cc:addr:python.org': 0.22; 'lets': 0.24; 'math': 0.24; 'mon,': 0.24; 'cc:2**0': 0.24; 'first,': 0.26; 'right.': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; '(on': 0.31; 'subject:what': 0.31; 'something': 0.35; 'test': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'nov': 0.38; 'that,': 0.38; 'subject:can': 0.39; 'sure': 0.39; 'dave': 0.60; 'numbers': 0.61; 'happen': 0.63; 'sum': 0.64; 'approaches': 0.68; 'angel': 0.91; 'to:none': 0.92 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=Eb1SO5NgQ2XZSoyF9KXfM140lk1XCJfwfxyiBUkAm+I=; b=ZUHjI92Ide8xcg6AsI+kVKsWlNjWjKqQebkfCuPiYi5vvCA0ZoVvhTsqNzagZ31H6c XJZUF2yfVzTwOXN4To8oXMBVUPPUF5vdCUUV3TDDf6EsqX9YUtmxZiOSBVpR30/EOIl1 VioZwmXgYeFgvwH8jU2Sq+vS8faSsZKOJLFtvi+ieFJl3q2K4SwIka8fEvrn4XBWrw/y UQBt+kTXfg6ycm5DdP5r+EXz3UZVBpSOg+Q4yJ8DBW4RMnD1biNgAj45/gzJJDlTARNS tK/nKR7uzCyAZinuvDEJaa7JHj9usKtcaEmEhaum4iITUExwcmVwp0GBt4TIOVd5tcui IHZA== MIME-Version: 1.0 X-Received: by 10.50.136.134 with SMTP id qa6mr12630450igb.2.1414966376131; Sun, 02 Nov 2014 14:12:56 -0800 (PST) In-Reply-To: <5456AB26.4060503@davea.name> References: <957d3844-9b9a-47b7-892f-b7660aa40d88@googlegroups.com> <4c0d5apoa3455vmkgdtp7nn25pl85fgmoh@4ax.com> <5456AB26.4060503@davea.name> Date: Mon, 3 Nov 2014 09:12:56 +1100 Subject: Re: what can i do to improve my skill after finished python course on codecademy From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 13 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1414966385 news.xs4all.nl 2929 [2001:888:2000:d::a6]:38871 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:80143 On Mon, Nov 3, 2014 at 9:07 AM, Dave Angel wrote: > Brute force would take a few millenia, as something like > ans = sum(range( BIG ) - sum(range(1000)) > > But just knowing the math lets you simplify it to something like > ans = (1000 + BIG) * (BIG - 1000) / 2 Suggestion: Master the brute-force approach first, and use that (on small ranges) to verify the simplified version. And if you already happen to know the sum of all numbers from 1 to 100, say, then you can test both approaches against that, to be sure they're right. ChrisA