#include <assert.h>
#include <stdio.h>
#define START (0)
#define RED_END (START + 19)
#define GREEN_END (RED_END + 22)
#define BLACK_END (GREEN_END + 28)
#define WHITE_END (BLACK_END + 19)
#define YELLOW_END (WHITE_END + 14)
#define ORANGE_END (YELLOW_END + 8)
#define END (ORANGE_END)
#define RED_BIT (1 << 0)
#define GREEN_BIT (1 << 1)
#define BLACK_BIT (1 << 2)
#define WHITE_BIT (1 << 3)
#define YELLOW_BIT (1 << 4)
#define ORANGE_BIT (1 << 5)
#define PICK_NUM (4)
int allDiffColor(int ball[])
{
char hitCheck = 0;
int i;
for (i = 0; i < PICK_NUM; ++i)
{
if (ball[i] < RED_END)
{
if (hitCheck & RED_BIT)
{
return 0;
}
else
{
hitCheck |= RED_BIT;
}
}
else if (ball[i] < GREEN_END)
{
if (hitCheck & GREEN_BIT)
{
return 0;
}
else
{
hitCheck |= GREEN_BIT;
}
}
else if (ball[i] < BLACK_END)
{
if (hitCheck & BLACK_BIT)
{
return 0;
}
else
{
hitCheck |= BLACK_BIT;
}
}
else if (ball[i] < WHITE_END)
{
if (hitCheck & WHITE_BIT)
{
return 0;
}
else
{
hitCheck |= WHITE_BIT;
}
}
else if (ball[i] < YELLOW_END)
{
if (hitCheck & YELLOW_BIT)
{
return 0;
}
else
{
hitCheck |= YELLOW_BIT;
}
}
else if (ball[i] < ORANGE_END)
{
if (hitCheck & ORANGE_BIT)
{
return 0;
}
else
{
hitCheck |= ORANGE_BIT;
}
}
else
{
}
}
return 1;
}
int main()
{
int ball[PICK_NUM] = {0};
int allCount = 0;
int hitCount = 0;
for (ball[0] = 0; ball[0] < END; ball[0]++)
{
for (ball[1] = 0; ball[1] < END; ball[1]++)
{
if (ball[0] == ball[1])
continue;
for (ball[2] = 0; ball[2] < END; ball[2]++)
{
if ((ball[0] == ball[2]) || (ball[1] == ball[2]))
continue;
for (ball[3] = 0; ball[3] < END; ball[3]++)
{
if ((ball[0] == ball[3]) || (ball[1] == ball[3]) || (ball[2] == ball[3]))
continue;
++allCount;
if (1 == allDiffColor(ball))
{
++hitCount;
}
}
}
}
}
printf("all: %d, hit: %d\n", allCount
, hitCount
); }