Here's a clean bash one:
#!/bin/bash
pool=( {a..d} )
for((i=0;i<${#pool[@]}-1;++i)); do
for((j=i+1;j<${#pool[@]};++j)); do
printf '%s\n' "${pool[i]}${pool[j]}"
done
done
and one more:
#!/bin/bash
pool=( {a..d} )
while ((${#pool[@]}>1)); do
h=${pool[0]}
pool=("${pool[@]:1}")
printf '%s\n' "${pool[@]/#/$h}"
done
They can be written as functions (or scripts):
get_perms_ordered() {
local i j
for((i=1;i<"$#";++i)); do
for((j=i+1;j<="$#";++j)); do
printf '%s\n' "${!i}${!j}"
done
done
}
or
get_perms_ordered() {
local h
while (("$#">1)); do
h=$1; shift
printf '%s\n' "${@/#/$h}"
done
}
Use as:
$ get_perms_ordered {a..d}
ab
ac
ad
bc
bd
cd
, ( -, - ), .,
get_withdraws_without_replacement() {
local n=$1 h r=()
shift
((n>0)) || return
((n==1)) && { gwwr_ret=( "$@" ); return; }
while (("$#">=n)); do
h=$1; shift
get_withdraws_without_replacement "$((n-1))" "$@"
r+=( "${gwwr_ret[@]/#/$h}" )
done
gwwr_ret=( "${r[@]}" )
}
:
$ get_withdraws_without_replacement 3 {a..d}
$ echo "${gwwr_ret[@]}"
abc abd acd bcd