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


Groups > comp.lang.python > #57620

Re: Obfuscated factorial

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <joshua.landau.ws@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.013
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'operator,': 0.09; 'cc:addr :python-list': 0.11; 'python': 0.11; 'to:addr:pearwood.info': 0.16; 'to:addr:steve+comp.lang.python': 0.16; "to:name:steven d'aprano": 0.16; 'sender:addr:gmail.com': 0.17; 'wrote:': 0.18; 'import': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'statement': 0.30; 'message- id:@mail.gmail.com': 0.30; 'assert': 0.31; "d'aprano": 0.31; 'steven': 0.31; 'received:google.com': 0.35; 'skip:f 40': 0.36; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type:content-transfer-encoding; bh=LyQsAZSCG0tWsXa5MLceZ+/XT/XLRjee1fkB6Q52EmA=; b=OEgRjvkL4EnT82qjY7pTzsj7UkTbl+XqPvXZtRWZP5ZA0Kd4W64DtX/nFI3TZ09xko Qbb1chzMDIfdSuvkzmBio5bWym1B8AhPIQd88R9SK7NNuauGCc9j+MpAzizz7PR2ehwv ULLQ7SMGmqeLM4gtSkWIJhSmqz6+11Q8oNUTTmdGS09l2QpaDYCDwIsqlgj79mtkxu7o Fz2QvmHrVg9NykawVbx6M6KyIHwQoXk3FNEoLtu3/m2S/xf52iO/c/TuAZbWgd6vzksV JS/D6neQYoPuA0a77KAOO7VkBBK2D2tbIht/c02ZwSpo96EkadT0WGqmThQkp4uXXeCY LJ1g==
X-Received by 10.112.146.200 with SMTP id te8mr5530764lbb.32.1382801570760; Sat, 26 Oct 2013 08:32:50 -0700 (PDT)
MIME-Version 1.0
Sender joshua.landau.ws@gmail.com
In-Reply-To <526badb4$0$29972$c3e8da3$5496439d@news.astraweb.com>
References <526badb4$0$29972$c3e8da3$5496439d@news.astraweb.com>
From Joshua Landau <joshua@landau.ws>
Date Sat, 26 Oct 2013 16:32:10 +0100
X-Google-Sender-Auth u_3hTZqock2EhEzps8hA7LCNbJA
Subject Re: Obfuscated factorial
To "Steven D'Aprano" <steve+comp.lang.python@pearwood.info>
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
Cc python-list <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
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.1581.1382801572.18130.python-list@python.org> (permalink)
Lines 25
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1382801572 news.xs4all.nl 15989 [2001:888:2000:d::a6]:35029
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:57620

Show key headers only | View raw


On 26 October 2013 12:55, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
> Just for fun:
...
> for i in range(16):
>     print(i, FactorialBuilder(i).build().calculate())

Python already supports the factorial operator, -ⵘ. You just have to import it.

# Import statement
ⵘ = type("",(),{"__rsub__":lambda s,n:(lambda f,n:f(f,n))(lambda
f,z:round((2.5066282746310002*(z+0j+7.5)**(z+0.5)*2.718281828459045**(-z-7.5)*(0.99999999999980993+676.5203681218851/(z+1)-1259.1392167224028/(z+2)+771.32342877765313/(z+3)-176.61502916214059/(z+4)+12.507343278686905/(z+5)-0.13857109526572012/(z+6)+9.9843695780195716e-6/(z+7)+1.5056327351493116e-7/(z+8))).real)if
z>=0.5 else 3.141592653589793/(__import__("math").sin(3.141592653589793*z)*f(f,1-z)),n)})()

assert 2-ⵘ == 2

assert 3-ⵘ == 6

assert 4-ⵘ == 24

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


Thread

Obfuscated factorial Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-10-26 11:55 +0000
  Re: Obfuscated factorial Vito De Tullio <vito.detullio@gmail.com> - 2013-10-26 14:50 +0200
  Re: Obfuscated factorial Chris Angelico <rosuav@gmail.com> - 2013-10-27 00:26 +1100
  Re: Obfuscated factorial Joshua Landau <joshua@landau.ws> - 2013-10-26 16:32 +0100
  Re: Obfuscated factorial Tim Chase <python.list@tim.thechases.com> - 2013-10-26 10:35 -0500
  Re: Obfuscated factorial Gene Heskett <gheskett@wdtv.com> - 2013-10-26 10:13 -0400
  Re: Obfuscated factorial Vito De Tullio <vito.detullio@gmail.com> - 2013-10-27 08:28 +0100

csiph-web