Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
19
Task/Permutations/UNIX-Shell/permutations-2.sh
Normal file
19
Task/Permutations/UNIX-Shell/permutations-2.sh
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
function permuteAn {
|
||||
# print all permutations of first n elements of the array A, with remaining
|
||||
# elements unchanged.
|
||||
local -i n=$1 i
|
||||
shift
|
||||
if (( n == 1 )); then
|
||||
printf '%s\n' "${A[*]}"
|
||||
else
|
||||
permuteAn $(( n-1 ))
|
||||
for (( i=1; i<n; ++i )); do
|
||||
local -i k
|
||||
(( k=n%2 ? 1 : i ))
|
||||
local t=$A[k]
|
||||
A[k]=$A[n]
|
||||
A[n]=$t
|
||||
permuteAn $(( n-1 ))
|
||||
done
|
||||
fi
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue