c -- 144 characters
Minified:
#define A(x) a[b[x%16]]
int c,b[]={4,8,0,1,2,4,6,0,3,4,5,2,8,6,7,2};int
T(int*a){for(c=0;c<16;c+=2)if(A(c)&A(c+1)&A(c+2))return A(c);return 0;}
Both returns count (one necessary and the other would need replacing with a space).
The array codes for the eight ways to win in triplets starting from even positions and taken mod 16.
Bitwise and trick stolen from Eric Pi.
More readable form:
#define A(x) a[b[x%16]]
// Compact coding of the ways to win.
//
// Each possible was starts a position N*2 and runs through N*2+2 all
// taken mod 16
int c,b[]={4,8,0,1,2,4,6,0,3,4,5,2,8,6,7,2};
int T(int*a){
// Loop over the ways to win
for(c=0;c<16;c+=2)
// Test for a win
if(A(c)&A(c+1)&A(c+2))return A(c);
return 0;
}
Testing scaffold:
#include
#include
int T(int*);
int main(int argc, char**argv){
int input[9]={0};
int i, j;
for (i=1; i