Question: Permutation with recursion for a list

Hello, 

I have a list of data {a,b,c,d} for which I need to create permutations without inbult function in Maple. The list of inputs is not fixed and it can contain aither one value or n-values. I was thinking about use of recursion in loops but it doesn't work as I was expected. Do you know please how to set a such recursive calculation with loops?
 

Result should be as follows for the list whole list range:

a+b

a+c

a+d

a+b+c

a+b+d
a+c+b
a+c+d

a+d+b

a+d+c

a+b+c+d

a+c+d+b

a+d+b+c

b+a

b+c

b+d

b+a+c

b+a+d

b+c+a

b+c+d

b+d+a

b+d+c

b+a+c+d

b+c+d+a

b+d+a+c

etc...

 

Comb1:=proc(S)
local G2::DataFrame,x,xs,i,j,T,k;

G2:=DataFrame([[]]);

if numelems(S)=0 then 
		return {}
		elif numelems(S)=1 then
			return {S}
		else 
			for i in seq(1..numelems(S))do
				for j in seq(1..numelems(S))do
					if i=j then
						next j
					end if;
			x:=S[j];
			xs:=S[i]+S[j];	

			#collect data into a dataframe
			G2:=Append(G2,DataSeries(<xs>),mode=row);

			#recursion
			for T in Comb1([xs]) do 
				for k in seq(1..numelems(S)) do
					if k=i or k=j then 
						next k
						end if;
				G2:=Append(G2,DataSeries(<[S[k]]+T>),mode=row);
				
					end do;
				end do;
			end do;
		end do;
	end if;
		
return G2;

end proc:

Comb1({a,b,c,d});

 

Please Wait...