Skip to main content
added 78 characters in body
Source Link
ilkkachu
  • 147.9k
  • 16
  • 268
  • 441

In Bash or something that supports arraysarrays, you could put the character set in an array and loop over the array again, prepending the characters again:

chars=( {a,b,c} )
doubles=()
triplets=()
for c in "${chars[@]}" ; do 
    doubles+=( ${chars[@]/#/$c} )
done
for c in "${chars[@]}" ; do 
    triplets+=( ${doubles[@]/#/$c} )
done
echo "${triplets[@]}"

that prints aaa aab aac ... ccc, and you can repeat as necessary for the longer ones, or turn it into a recursive function. (The ${var//} is a pattern substitution where # marks the start of the string. When it's applied to an array, it applies to all values of the array, one at a time.)

In Bash or something that supports arrays, you could put the character set in an array and loop over the array again, prepending the characters again:

chars=( {a,b,c} )
doubles=()
triplets=()
for c in "${chars[@]}" ; do 
    doubles+=( ${chars[@]/#/$c} )
done
for c in "${chars[@]}" ; do 
    triplets+=( ${doubles[@]/#/$c} )
done
echo "${triplets[@]}"

that prints aaa aab aac ... ccc, and you can repeat as necessary for the longer ones, or turn it into a recursive function. (The ${var//} is a pattern substitution where # marks the start of the string. When it's applied to an array, it applies to all values of the array, one at a time.)

In Bash or something that supports arrays, you could put the character set in an array and loop over the array again, prepending the characters again:

chars=( {a,b,c} )
doubles=()
triplets=()
for c in "${chars[@]}" ; do 
    doubles+=( ${chars[@]/#/$c} )
done
for c in "${chars[@]}" ; do 
    triplets+=( ${doubles[@]/#/$c} )
done
echo "${triplets[@]}"

that prints aaa aab aac ... ccc, and you can repeat as necessary for the longer ones, or turn it into a recursive function. (The ${var//} is a pattern substitution where # marks the start of the string. When it's applied to an array, it applies to all values of the array, one at a time.)

added 141 characters in body
Source Link
ilkkachu
  • 147.9k
  • 16
  • 268
  • 441

In Bash or something that supports arrays, you could put the character set in an array and loop over the array again, prepending the characters again:

chars=( {a,b,c} )
doubles=()
triplets=()
for c in "${chars[@]}" ; do 
    doubles+=( ${chars[@]/#/$c} )
done
echofor c in "${chars[@]}" ; do 
    triplets+=( ${doubles[@]/#/$c} )
done
echo "${triplets[@]}"

that prints aa ab ac ba bbaaa bcaab caaac cb... ccccc, and you can repeat as necessary for the longer ones, or turn it into a recursive function. (The ${var//} is a pattern substitution where # marks the start of the string. When it's applied to an array, it applies to all values of the array, one at a time.)

In Bash or something that supports arrays, you could put the character set in an array and loop over the array again, prepending the characters again:

chars=( {a,b,c} )
doubles=()
for c in "${chars[@]}" ; do 
    doubles+=( ${chars[@]/#/$c} )
done
echo "${doubles[@]}"

that prints aa ab ac ba bb bc ca cb cc, and repeat as necessary for the longer ones. (The ${var//} is a pattern substitution where # marks the start of the string.)

In Bash or something that supports arrays, you could put the character set in an array and loop over the array again, prepending the characters again:

chars=( {a,b,c} )
doubles=()
triplets=()
for c in "${chars[@]}" ; do 
    doubles+=( ${chars[@]/#/$c} )
done
for c in "${chars[@]}" ; do 
    triplets+=( ${doubles[@]/#/$c} )
done
echo "${triplets[@]}"

that prints aaa aab aac ... ccc, and you can repeat as necessary for the longer ones, or turn it into a recursive function. (The ${var//} is a pattern substitution where # marks the start of the string. When it's applied to an array, it applies to all values of the array, one at a time.)

Source Link
ilkkachu
  • 147.9k
  • 16
  • 268
  • 441

In Bash or something that supports arrays, you could put the character set in an array and loop over the array again, prepending the characters again:

chars=( {a,b,c} )
doubles=()
for c in "${chars[@]}" ; do 
    doubles+=( ${chars[@]/#/$c} )
done
echo "${doubles[@]}"

that prints aa ab ac ba bb bc ca cb cc, and repeat as necessary for the longer ones. (The ${var//} is a pattern substitution where # marks the start of the string.)