Ecco una possibile soluzione del problema mediante una procedura ricorsiva :
codice:
program Permuta;


var
 strIn:string;
 strNew:string;
 len:integer;
 i:integer;
 count:integer;
 
procedure GenPerm(strSub:string;index:integer);

 var
  strTemp:string;
  i:integer;
 begin
  strTemp:=strSub;
  for i:=1 to len do
  begin
   if strTemp[i]=' ' then
   begin
    strTemp[i]:=strIn[index];
    if index=len then
    begin
     writeln(strTemp);
     count:=count+1;
    end
    else GenPerm(strTemp,index+1);
   end;
   strTemp:=strSub;
  end;
 end;
 
begin
 count:=0;
 strNew:='';
 readln(strIn);
 len:=Length(strIn);
 for i:=1 to len do
  strNew:=strNew+' ';
 GenPerm(strNew,1);
 writeln('Numero delle permutazioni: ',count);
 readln;
end.
Saluti .