Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #57620
| References | <526badb4$0$29972$c3e8da3$5496439d@news.astraweb.com> |
|---|---|
| From | Joshua Landau <joshua@landau.ws> |
| Date | 2013-10-26 16:32 +0100 |
| Subject | Re: Obfuscated factorial |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1581.1382801572.18130.python-list@python.org> (permalink) |
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 | Next — Previous in thread | Next in thread | Find similar | Unroll 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