0

Assuming I have the values A B C D E and eight places 1 2 3 4 5 6 7 8. How can I get all possible combinations printed with two- and three-time repetitions?

Example:

1 2 3 4 5 6 7 8 _______________ A A B B C C D E A B B C C D D E (and so on...) A A A B B C D E A B B B C C D E (and so on...) 

Which combination is followed by which is not further important. There should not be any missing values like AABBCCDD (where E is missing)

1
  • 1
    What exactly is your problem? 1. Finding an algorithm? 2. Implementing the algorithm in bash? If 1 then ask about the algorithm first. If 2 then show the algorithm (or a link to it) in the question. I think this question is not specifically related to UNIX or Linux and might better fit on stackoverflow.com. Commented Oct 27, 2022 at 17:26

1 Answer 1

1

A crude approach with zsh/ksh93/bash could be:

printf '%s\n' {A..E}{A..E}{A..E}{A..E}{A..E}{A..E}{A..E}{A..E} | sed '/A/!d; /B/!d; /C/!d; /D/!d; /E/!d; /\(.\)\(.*\1\)\{3\}/d' 

Where we use zsh-style {A..E} to generate all 58 combinations from AAAAAAAA to EEEEEEEE, and sed removes the ones that don't contain A, or don't contain B, C, D, E or more than 3 of the same character.

Add ;s/./ &/2g (GNU sed) or ;s/./ &/g;s/ // (any sed) to the sed code to insert spaces in-between the letters.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.