proc optmodel;
num n = 5;
set CARDS = 0..3^n-1;
set POSITIONS = n-1..0 by -1;
num digit {c in CARDS, k in POSITIONS};
num curr;
for {c in CARDS} do;
curr = c;
for {k in POSITIONS} do;
digit[c,k] = floor(curr/3^k);
curr = curr - 3^k * digit[c,k];
end;
end;
set SETS = {c1 in CARDS, c2 in CARDS, c3 in CARDS: c1 < c2 < c3 and
and {k in POSITIONS} (mod(sum {c in {c1,c2,c3}} digit[c,k], 3) = 0)};
var Select {CARDS} binary;
max NumSelected = sum {c in CARDS} Select[c];
con NoSet { in SETS}:
sum {c in {c1,c2,c3}} Select[c] <= 2;
solve;
set SUPPORT = {c in CARDS: Select[c].sol > 0.5};
print {c in SUPPORT, k in POSITIONS} digit[c,k];
quit;