This script does Factorials or Permutations or Combinations or all of them for you. Just set up the const then hit run.
PHP Code:
var
DoFactorial, DoCombination, DoPermutation: Boolean;
const
{Permutation Setup}
Book = 4; //How many objects there are.
Shelf = 2; // How many slots there are.
{Combination Setup}
Candy = 4; //How many objects there are.
Jars = 2; // How many slots there are.
{Factorial Setup}
Num = 4; // Number to factorize.
procedure Setup;
begin
case Lowercase(Readln('Do Factorials? Yes/No')[1]) of
'y': DoFactorial:= True;
'n': DoFactorial:= False;
end;
case Lowercase(Readln('Do Combinations? Yes/No')[1]) of
'y': DoCombination:= True;
'n': DoCombination:= False;
end;
case Lowercase(Readln('Do Permutations? Yes/No')[1]) of
'y': DoPermutation:= True;
'n': DoPermutation:= False;
end;
end;
function Factorial(z:Integer):Integer;
var
x, a:Integer;
begin
a:=z;
for x:= 1 to z-1 do
begin
a:= a* (z-x);
end;
Result:= A;
end;
function Permutation(z, e:Integer):Integer;
var
R, P:Integer;
begin
R:= Factorial(z);
P:= z-e;
Result:= R div Factorial(P);
end;
function Combination(H, L:Integer):Integer;
var
S, O, Q:Integer;
begin
S:= Factorial(H);
Q:= H-L;
O:= Factorial(L)*Factorial(Q);
Result:=S div O;
end;
procedure RP;
begin
if (DoFactorial) then
begin
Writeln('The factorial of '+IntToStr(Num)+' is '+IntToStr(Factorial(Num)));
Writeln(' ');
end;
if (DoCombination) then
begin
Writeln('The number of Combinations for '+InttoStr(Candy)+' thing[s] taken '+Inttostr(Jars)+',');
Writeln('at a time is '+IntToStr(Combination(Candy, Jars)));
Writeln(' ');
end;
if (DoPermutation) then
begin
Writeln('The number of Permutations for '+InttoStr(Book)+' thing[s] taken '+Inttostr(Shelf)+',');
Writeln('at a time is '+IntToStr(Permutation(Book, Shelf)));
Writeln(' ');
end;
end;
begin
SetUp;
RP
end.