I found this script and would like to find a specific combination by its number in the sequence.
If 4312 comes in position 23, can this combination be found just by calculating the sequence number 23 without comparing and running through all possible sequences?
Otherwise it takes too long with bash and I don't know other languages well enough to modify the code. Moreover, bash is more stable than python or java when it comes to updates and changes to the code structure.
I was looking for a calculation method but unfortunately I'm a math idiot and Spanish is probably easier to understand than knowing which is the correct calculation method and then applying it to an array which only shows the desired combination sequence by specifying the position in the sequence.
Code: Select all
n=23; i=0; while read in; do
nr=$(sed -r "s/(.)/\1\n/g" <<<$in | sort | uniq | wc -l)
[[ $nr == 5 ]] && i=$[$i+1]
[[ $nr == 5 && $n == $i ]] && out=$in && break
done <<<$(echo -e {1..4}{1..4}{1..4}{1..4}"\n")
echo $out #4312