Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #57650
| Path | csiph.com!usenet.pasdenom.info!news.franciliens.net!fdn.fr!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <gheskett@wdtv.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | UNSURE 0.366 |
| X-Spam-Level | *** |
| X-Spam-Evidence | '*H*': 0.46; '*S*': 0.19; 'output': 0.05; 'def': 0.12; '1):': 0.16; 'int):': 0.16; 'pythonic': 0.16; 'soap,': 0.16; 'valueerror': 0.16; ':-)': 0.16; 'saying': 0.22; 'cheers,': 0.24; 'header:In-Reply-To:1': 0.27; 'raise': 0.29; '120': 0.31; "d'aprano": 0.31; 'steven': 0.31; 'class': 0.32; 'skip:_ 10': 0.34; 'received:66': 0.35; 'but': 0.35; 'skip:f 40': 0.36; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'space': 0.40; 'dangerous': 0.60; 'received:unknown': 0.61; 'header :Message-Id:1': 0.63; 'skip:n 10': 0.64; 'charset:windows-1256': 0.64; 'more': 0.64; 'saturday': 0.68; 'million': 0.74; 'received:204': 0.75; 'hand': 0.80; 'citizens.': 0.84; 'nice,': 0.84; 'number):': 0.84; 'boxes': 0.91; 'hands': 0.96; '2013': 0.98 |
| X-Spam-Status | No, score=1.4 required=5.0 |
| X-Spam-Level | + |
| From | Gene Heskett <gheskett@wdtv.com> |
| To | python-list@python.org |
| Subject | Re: Obfuscated factorial |
| Date | Sat, 26 Oct 2013 10:13:33 -0400 |
| References | <526badb4$0$29972$c3e8da3$5496439d@news.astraweb.com> |
| In-Reply-To | <526badb4$0$29972$c3e8da3$5496439d@news.astraweb.com> |
| MIME-Version | 1.0 |
| Content-Type | Text/Plain; charset="windows-1256" |
| Content-Transfer-Encoding | 7bit |
| X-Mailman-Approved-At | Sat, 26 Oct 2013 21:16:48 +0200 |
| 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.1597.1382815010.18130.python-list@python.org> (permalink) |
| Lines | 77 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1382815010 news.xs4all.nl 15867 [2001:888:2000:d::a6]:55853 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:57650 |
Show key headers only | View raw
On Saturday 26 October 2013 10:12:33 Steven D'Aprano did opine:
> Just for fun:
>
>
> class Numberator:
> def __init__(self, number):
> self.__number = number
> def evaluate(self):
> return self.__number
>
> class Multiplier:
> def __init__(self, multiplier, multiplicand):
> self.multiplier = multiplier
> self.multiplicand = multiplicand
> def evaluate(self):
> return self.multiplier * self.multiplicand.evaluate()
>
> class FactorialBuilder:
> def __init__(self, number):
> if not isinstance(number, int):
> raise TypeError
> if number < 0:
> raise ValueError
> self.__number = number
> def build(self):
> multiplicand = Numberator(1)
> for n in range(2, self.__number + 1):
> multiplicand = Multiplier(n, multiplicand)
> return Factorialiser(multiplicand)
>
> class Factorialiser:
> def __init__(self, evaluatorix):
> self.__evaluatorix = evaluatorix
> def calculate(self):
> return self.__evaluatorix.evaluate()
>
> for i in range(16):
> print(i, FactorialBuilder(i).build().calculate())
>
>
>
> And the output is:
>
> 0 1
> 1 1
> 2 2
> 3 6
> 4 24
> 5 120
> 6 720
> 7 5040
> 8 40320
> 9 362880
> 10 3628800
> 11 39916800
> 12 479001600
> 13 6227020800
> 14 87178291200
> 15 1307674368000
>
Nice, but will it go to 70? :)
>
> It goes without saying that this isn't Pythonic :-)
Cheers, Gene
--
"There are four boxes to be used in defense of liberty:
soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
"Out of register space (ugh)"
-- vi
A pen in the hand of this president is far more
dangerous than 200 million guns in the hands of
law-abiding citizens.
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