While practicing coding problems, I ran into this challenging problem:
Say I have a 7-variable equation, (A+B+C+C+D+B)(E+F+B+C)(G+F+F), and a huge list with up to 3500 numbers:
A 1, 2, 3; B 1, 2; C 9, 1; D 1; E 2; F 1; G 1
This list basically gives all the possible values that each variable can have. The question is, how many ways can I choose values of variables such that the resulting number is a multiple of seven?
For example, I could choose from the above list A = 1, B = 1, C = 1, D = 1, E = 2, F = 1, G = 1. This would make the number (1+2+1+1+1+1)(2+1+1+1)(1+1+1) = 35, which is indeed a multiple of seven.
My solution was to test every possible combination of the seven variables, and check if that sum was a multiple of seven. However, that solution is obviously very slow. Does anyone have a more efficient solution for this problem?