There are different ways to solve the problem, but one possible algorithm to count the combinations is:
count_valid and count_invalid, to zero.a and b between 0 and 6, including 0 and 6.a+b==6. If true, increment count_valid by 1. If false, increment count_invalid by 1.count_valid+count_invalid.Here's the code that implements this algorithm in MATLAB:
main.m317 chars14 lines
The output of this code is: Number of combinations: 28.
gistlibby LogSnag