Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re^2: Exponential Function Programming

by Dominus (Parson)
on Nov 23, 2007 at 19:45 UTC ( #652646=note: print w/replies, xml ) Need Help??

in reply to Re: Exponential Function Programming
in thread Exponential Function Programming

sub my_factorial { ... if($n == 0) { $r=0; } return $r; }
Your function says that 0 factorial is 0. But it's not; it's 1.

Replies are listed 'Best First'.
Re^3: Exponential Function Programming
by blazar (Canon) on Nov 24, 2007 at 13:42 UTC

    Perl 6 is very generous in this:

    pugs> sub postfix:<!> (Int $n) { [*] 1..$n } undef pugs> say $_! for ^10 1 1 2 6 24 120 720 5040 40320 362880 undef

    (I personally believe that I've posted this before here and in different media, but that's jut because it's quite about the only thing I can actually do in pugs ATM.)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://652646]
[stevieb]: Thanks hippo, as do I, as if it's not, hardware peripherals or sensors could be destroyed (code has to be reliable when dealing with input/output voltages)
[hippo]: Aha - more Pi-based projects?
[stevieb]: yeah digital potentiometer

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (22)
As of 2017-01-20 16:53 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (176 votes). Check out past polls.