Need a hint?
find_all_triads
In order to find all of the Triads, you need to test every combination of three cards to see if each one forms a Triad. You should use a nested for loop to test them all.
However, you have to be careful when constructing this loop. If you check all combinations, here are some of the triples of cards you’ll check:
Test the triad i=0, j=0, k=0 -> you always want i, j, and k to be Test the triad i=0, j=0, k=1 -> different, but here you are including the Test the triad i=0, j=0, k=2 -> same card multiple times ... Test the triad i=0, j=1, k=2 -> eventually you'll start testing some triple Test the triad i=0, j=1, k=3 -> you actually wanted to test Test the triad i=0, j=1, k=4 Test the triad i=0, j=1, k=5 ... Test the triad i=0, j=2, k=1 -> but this triple is the same as (0, 1, 2) ... Test the triad i=1, j=0, k=2 -> ...and this triple is the same as (0, 1, 2) ... Test the triad i=1, j=0, k=2 -> ...and this triple is the same as (0, 1, 2) ... Test the triad i=1, j=2, k=0 -> ...and this ... Test the triad i=2, j=0, k=1 -> ...and this ... Test the triad i=2, j=1, k=0 -> ...and this
So the hint is that you want to use a nested for loop, but you want to find a way to make sure you never have a duplicate card in your Triad (e.g. (0, 0, 0)
or (1, 2, 1)
) and you never want to test the same combination twice (e.g. (0, 1, 2)
and (1, 0, 2)
).
Ask questions in office hours or ninja sessions if you’re still stuck!