Then, we have to list all wanted results. Which is basically all possible set of pairs, and each set has two wanted result where the first pair adds up to 7 and the second pair adds up to 9, or vice-versa. And which we got:
(D1+D2==7 and D3+D4==9) or (D1+D2 ==9 and D3+D4==7)
(D2+D3==7 and D1+D4==9) or (D2+D3 ==9 and D1+D4==7)
(D2+D4==7 and D1+D3==9) or (D2+D4 ==9 and D1+D3==7)
After that, we can make the code that runs the simulation multiple time and when there is a run that has one of the wanted result, it return a 1, likewise, it returns 0.