Apologies if this looks like another problem – there are quite a lot of solutions and I didn’t find what I’m looking for, but I may well have missed it. Also apologies if title isn’t best description – not sure how else to word it.
I have five ‘features’ as strings, e.g.:
$height $width $depth $length $colour
I want to get all the different unique combinations starting with 5 and going down to 1 e.g.:
5: $height $width $depth $length $colour
4: $height $width $depth $length
4: $height $width $depth $colour
4: $height $width $length $colour
4: $height $depth $length $colour
4: $width $depth $length $colour
...
and so on
...
1: $height
1: $width
1: $depth
1: $length
1: $colour
I don’t know if it makes a difference, but in code I plan to use && and !$string, e.g.:
4: $height && $width && $depth && $length && !$colour
4: $height && $width && $depth && !$length && $colour
4: $height && $width && !$depth && $length && $colour
4: $height && !$width && $depth && $length && $colour
4: !$height && $width && $depth && $length && $colour
and so on.
I was fine doing this by hand when I had 4 features, but with 5 it’s too much!
I thought putting the variables in a hash would may be good starting point, but as for the actual algorithm… Any help appreciated!
Edit: just realised it may not be clear, but I want to be able to ‘query’ each combination as they will be in if/elsif statements, so if (h && w && !d ...)
Encode a configuration as a 5 bit integer and just iterate from 0 to 25-1.