Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: factorialmath.

by BooK (Curate)
on Jun 24, 2002 at 13:17 UTC ( #176773=note: print w/replies, xml ) Need Help??


in reply to factorialmath.

Let the effort be in explaining this code, if the AM ever uses it.

#!/usr/bin/perl # There is everything you need: # a sentinel, $f{0} = sub { 1 }; # a recursive function, sub f { $f{$n = pop()-1} ||= sub { f($n) }; ($n+1) * $f{$n}->(); } # a call to the recursive function... print f(shift);

I hope it doesn't need to pass -w and use strict... ;-) And what did he mean, test if the parameter is a number?!

Replies are listed 'Best First'.
Re: Re: factorialmath.
by Hero Zzyzzx (Curate) on Jun 24, 2002 at 14:37 UTC

    Student: Umm, well see it has something called a sub, and when you "pop" it it pulls the number and . . .

    Professor: F-

    -Any sufficiently advanced technology is
    indistinguishable from doubletalk.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://176773]
help
Chatterbox?
[james28909]: hi, im james, and i am bat shit crazy. xD
[james28909]: crazy or genius....
[Eily]: hi bat shit crazy, I'm eily
[LanX]: hello James
[james28909]: lol
[james28909]: i honestly didnt thin kanyone was going to respond, or was even paying attention :l
[Eily]: well if you say something like that someone has to pay attention by law
[Eily]: Murphy's law to be precise

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (12)
As of 2017-12-13 17:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (373 votes). Check out past polls.

    Notices?