[erlang-questions] Frying pan bug
Joe Armstrong
erlang@REDACTED
Fri Mar 2 15:31:45 CET 2012
Silly me - thanks anyway
/Joe
On Fri, Mar 2, 2012 at 12:56 PM, Kostis Sagonas <kostis@REDACTED> wrote:
> On 03/02/2012 12:42 PM, Joe Armstrong wrote:
>>
>> -module(bug).
>> -compile(export_all).
>>
>> bug() -> p(0.3, 4, 11).
>>
>> c(N, M) -> fac(M) div (fac(N)*fac(M-N)).
>>
>> fac(0) -> 1;
>> fac(N) -> N*fac(N-1).
>>
>> p(P, M, N) -> 1.0 - math:pow(1-P, N-M)*c(N, M).
>>
>> Running bug:bug() tries to turn my machine into a frying pan
>>
>> Should this be renamed frying_pan.erl ?
>
>
> No,perhaps it should be renamed to "factorial_not_defined_properly.erl".
>
> If you write the factorial function as follows:
>
> fac(0) -> 1;
> fac(N) when N > 0 -> N*fac(N-1).
>
> you will be able to see what's happening.
>
> Cheers,
> Kostis
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
More information about the erlang-questions
mailing list