So what do you think is the problem with the code currently, and where are you stuck?
Why is vortex
defined but not used?
This looks like the kind of problem where the more math properties you can extract from the problem, the less code you need to write.
Since this question asks for distinct sets of 3 letters where permutations of them are considered the same, iterating in one direction only and reducing the number of items checked in each iteration is a common strategy.
My main strategy is to “keep moving forward”, and sub-strategy is to simplify the problem down from 3 letters to 2 letters.
So assuming i only needed to pick 2 letters, and for the convenience of implementing the iteration so it only moves in 1 direction from left to right, i begin by left flushing my choices and picking A,B for the 1st outer iteration. In future outer iterations, i would pick {A,C} {A,D}…{A,I}. Notice that this is kind of like finding all the possible pairs given a list of letters. What this ensures is that the first 2 letters at least are unique, at least for the outer iteration.
Now we need 3 letters, so this is what the inner iteration is for. For the 1st outer iteration of {A,B}, i would add {C}, {D}…{J} to the inner iteration to form {A,B,C}, {A,B,D}, …{A,B,J}. Important to note that the 3rd letter chosen must be to the right of the 2nd letter to prevent counting a 3 letter combination previously accounted for in a previous outer iteration. The previous paragraph describing outer iteration ensures that the 1st 2 letters will never duplicate, and by starting the inner iteration after the 2nd letter (moving right or left for 3rd letter doesn’t matter, for coding/thought clarity, just move right for both outer/inner loops) , it ensures that all 3 letter combinations generated are unique.
After all {A,B,?} are accounted, we move to the 2nd outer iteration, A stays there, B moves to C, inner iteration starts at D to end. So it becomes {A,C}+{D/E/F…J}.Repeat the previous until {A,I} is used. Now all of A has finished, move to {B,C},{B,D},…{B,I}, then move to {C,D}, you get the pattern now.
If you agree with the above argument, how would you implement it in code? You can use nCr calculators to verify the code. To generate listo
, you can do easier syntax using list('ABCDE...')
to save typing quotes and commas