! Print permutations.
! Compile with 'tx fac.t'

const	MAX	=	32;


permute(s, k, n) do
	var	i, j, t;
	var	done[MAX], m;

	m := 0;
	ie (k = n) do
		writes(s); newline();
	end
	else for (i=n, k) do
		for (j=0, m) if (s[i] = done[j]) leave;
		if (j = m) do
			t := s[i]; s[i] := s[n]; s[n] := t;
			permute(s, k, n+1);
			t := s[i]; s[i] := s[n]; s[n] := t;
			done[m] := s[i]; m := m+1;
		end
	end
end


do
	var	input[81], k;

	while (1) do
		if (\reads(input, 81)) leave;
		k := 0;
		while (input[k]) k := k+1;
		k := k-1;
		if (input[k-1] = '\r') k := k-1;
		input[k] := 0;
		permute(input, k, 0);
	end
end

