Blumblebee
2009-06-05 19:19:44
So with some help from Widget on irc, I finally managed to get a working factorial calculator (n!) and nCr (n Choose r: where order is not important) and nPr(n Pick r: where Order is Important). It works to a point, keep in mind use low decimals ish. ex. 40! results in over a 47 decimal chain which scar cannot process. Exceeding the limit of scars calculation abilities will result in Scar overflowing, meaning your calculations will be off etc, so just dont do it :p
Example:
returns
hope this somewhat helps anyone doing perms and coms, it helped me ;)
So have fun with it, I might add some more stuff later, like calculating probability or something. (yeah the code isnt too efficient but idc)
Example:
Factorial(4);
returns
4! = 24
hope this somewhat helps anyone doing perms and coms, it helped me ;)
program New;
Function Factorial(n: Int64): Int64;
var
i: Int64;
a : integer;
begin
i := 1;
for a := 1 to n do
i := i * a;
Result := i;
writeln(Int64ToStr(n)+'! = '+Int64ToStr(Result));
end;
Function nCr(n, r: Int64): Int64;
var a, b, c, d, e: Int64;
begin
a := Factorial(n);
b := n-r;
c := Factorial(b);
d := c*Factorial(r);
e := a/d;
WriteLn(Int64ToStr(a)+' div '+Int64ToStr(d)+' = '+Int64ToStr(e));
Result := e;
writeln(Int64ToStr(n)+' C '+Int64ToStr(r)+' = '+Int64ToStr(Result));
end;
Function nPr(n, r: Int64): Int64;
var a, b, c, d: Int64;
begin
a := Factorial(n);
b := n-r;
c := Factorial(b);
d := a/c;
Result := d;
writeln(Int64ToStr(n)+' P '+Int64ToStr(r)+' = '+Int64ToStr(Result));
end;So have fun with it, I might add some more stuff later, like calculating probability or something. (yeah the code isnt too efficient but idc)