Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.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.039 X-Spam-Evidence: '*H*': 0.92; '*S*': 0.00; 'suppose': 0.05; 'integers': 0.09; 'recursion': 0.09; 'pm,': 0.11; 'examples': 0.12; 'wrote:': 0.14; 'algorithmic': 0.16; 'fibonacci': 0.16; 'naive': 0.16; 'algorithm': 0.16; 'stack': 0.16; 'fine': 0.18; 'tue,': 0.20; 'language': 0.20; 'maybe': 0.21; 'saying': 0.22; 'header:In-Reply-To:1': 0.22; '64-bit': 0.23; 'issues.': 0.23; 'point,': 0.25; 'subject: -- ': 0.25; 'demonstrate': 0.26; 'chris': 0.27; 'message-id:@mail.gmail.com': 0.28; 'url:edu': 0.28; '(as': 0.29; 'nobody': 0.29; 'probably': 0.30; 'switch': 0.31; 'anyone': 0.31; 'to:addr:python-list': 0.32; 'done': 0.32; 'idea': 0.32; 'richard': 0.33; 'with.': 0.33; 'sometimes': 0.33; 'rather': 0.36; 'feature': 0.36; 'should': 0.37; 'received:209.85': 0.37; 'issue': 0.37; 'apr': 0.38; 'received:google.com': 0.38; 'but': 0.38; 'unless': 0.38; 'question,': 0.39; 'somewhat': 0.39; 'to:addr:python.org': 0.39; 'received:209': 0.39; 'include': 0.40; 'header:Received:5': 0.40; 'simple': 0.60; '2011': 0.62; 'url:net': 0.62; 'here': 0.65; 'paper': 0.68; 'become': 0.70; 'url:htm': 0.72; 'citing': 0.84; 'received:209.85.210.174': 0.84; 'received:mail- iy0-f174.google.com': 0.84; '12.': 0.93; 'only:': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type; bh=G1k/VICcvYMLGiOxBbumTi75ej0TUBBQQ9jFv8HEuWk=; b=dS2qfvl3aXehjw0JfdRocTRbHdvA8FLjT4pqNUdxWrOpngmzH7tylssSUTAjX6SVKd z2D1i9LqlWsVMXVKbhxdL8BwD5Tcr9FiO79xaXIDfZRxQOKOPBfD7y1HtxFujolTGRgw JYXGatcT+Tp/Dr4Dts3D5SlmE7jiUTare4w5U= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=KmqgEb7NA1qIx2imRlZJxr2sLK+UgNn+aZ4Wtn/vShEzM5JnYVmc+bN7O2p1wgMcyA qRCN0hlq3FGN3y5842GQqV8cPHI9Gwe8OWxqherZ8WRsFCVDlgYBic7Ss/TdlePuQaQn jfhzTUsUcTB6kXMVanwolPMx+u7r9XK5R/+bo= MIME-Version: 1.0 In-Reply-To: References: <8abff237-5ccd-4eb6-85c8-cdc9e87520b7@bl1g2000vbb.googlegroups.com> <90v871FkuaU1@mid.individual.net> <4daaa8a0$0$29986$c3e8da3$5496439d@news.astraweb.com> <4DAB9C3F.20801@ieee.org> <9143muFb0mU1@mid.individual.net> Date: Tue, 19 Apr 2011 17:01:59 +1000 Subject: Re: Feature suggestion -- return if true From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 36 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1303196523 news.xs4all.nl 81485 [::ffff:82.94.164.166]:55200 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:3544 On Tue, Apr 19, 2011 at 4:42 PM, Jussi Piitulainen wrote: > Factorials become an interesting demonstration of recursion when done > well. There's a paper by Richard J. Fateman, citing Peter Luschny: > > > > > Fateman's "major conclusion is that you should probably not use the > 'naive' factorial programs for much of anything". I take this to > include their use as examples of recursion, unless the purpose is to > make the idea of recursion look bad. " And here is an algorithm which nobody needs, for the Simple-Minded only: long factorial(long n) { return n <= 1 ? 1 : n * factorial(n-1); } Do not use it if n > 12. " I suppose the n > 12 issue is based on the assumption that sizeof(long)==4. That's not an algorithmic question, that's a return type issue... not to mention a rather naive assumption. 64-bit integers let you go to n == 20 (iirc), and if you go bignum, even that simple algorithm will be fine for up to n == 500 or so without stack issues. But sometimes you need a simple and well-known algorithm to demonstrate a language feature with. Maybe we should switch to Fibonacci instead... Anyone for caramel sauce? http://www.dangermouse.net/esoteric/chef_fib.html (As a side point, I have become somewhat noted around the house for always saying "Fibonacci" whenever caramel sauce is mentioned...) Chris Angelico