Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A QUESTION ABOUT PASCAL

Status
Not open for further replies.

mobilef

IS-IT--Management
Sep 30, 2005
10
HK
If I have the following information
two 12-seat-table
two 11-seat-table
one 10-seat-table
How to show all the probabaility?
12 12 11 11 10
12 11 12 11 10
12 10 11 12 11
...
...

THANK YOU

 
I think you mean permutations, not probability?
 
yes, I am sorry.
My English isn't good enough. ><
 
usualy for this kind of problem you should use backtracking.
i dind'n quite undesrstand the problem but if you explain it to me i could show you how the program would look like
 
program F_Tables;
var
Permutations:integer;

{ ------------------------------------------------------------ }
function AnsIsLegal(S:string):boolean;
var
aCOunt,
bCOunt,
cCOunt:integer;
i:integer;
begin
aCount := 0;
bCount := 0;
cCount := 0;
for i := 1 to 5 do
begin
case S of
'A': inc(aCOunt);
'B': inc(bCOunt);
'C': inc(cCOunt);
end;
end;
result := true;
if aCOunt <> 2 then
result := false;
if bCOunt <> 2 then
result := false;
if cCOunt <> 1 then
result := false;
end;

{ ------------------------------------------------------------ }
procedure AddToLIst(S:string);
var
i:integer;
begin
if AnsIsLegal(S) then
begin
for i := 1 to 5 do
case S of
'A': write('12 ');
'B': write('11 ');
'C': write('10 ');
end; { case }
writeln('');
inc(Permutations);
end;
end;
{ ------------------------------------------------------------ }
procedure FindAll;
var
Ac,Bc,Cc,Dc,Ec:Char;
S:string;
begin
Permutations := 0;
For Ac := 'A' to 'C' do
For Bc := 'A' to 'C' do
For Cc := 'A' to 'C' do
For Dc := 'A' to 'C' do
For Ec := 'A' to 'C' do
begin
S := Ac + Bc + Cc + Dc + Ec;
AddToList(S);
end;
writeln(Permutations,' Permutations found');
writeln('press return to exit');
readln(S); // in case running in dos window then keep window open
end;
{ ------------------------------------------------------------ }


begin { F_Tables }
FindAll;
end.

John Pears, Coventry, England.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top