summaryrefslogtreecommitdiff
path: root/euler90.c
blob: b5142699e818d4cecd30db15e4b1493d6178c6ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <stdio.h>
#include <string.h>
#include <assert.h>

char dices[210][6];

#define FOR(i) for (a[i] = a[i-1]+1; a[i] < 10; a[i]++)

void init()
{
	char a[6];
	int k = 0;
	for (a[0] = 0; a[0] < 10; a[0]++) {
		FOR(1) {
			FOR(2) {
				FOR(3) {
					FOR(4) {
						FOR(5) {
							memcpy(dices[k], a, sizeof(a));
							k++;
						}
					}
				}
			}
		}
	}
	assert(k == 210);
}

int matches(char c, char dic[])
{
	for (int i = 0; i < 6; i++) {
		if (c == dic[i] ||
				((c == 6 || c== 9) && (dic[i] == 6 || dic[i] == 9)))
			return 1;
	}
	return 0;
}

int ok(int x, int y)
{
	const char sqrs[9][2] = {
		{0, 1}, {0, 4}, {0, 9}, {1, 6}, {2, 5}, {3, 6}, {4, 9},
		{6, 4}, {8, 1}
	};
	for (int i = 0; i < 9; i++) {
		if (matches(sqrs[i][0], dices[x])
				&& matches(sqrs[i][1], dices[y]))
			continue;
		if (matches(sqrs[i][0], dices[y])
				&& matches(sqrs[i][1], dices[x]))
			continue;
		return 0;
	}
	return 1;
}

int main()
{
	int count = 0;
	init();
	for (int i = 0; i < 210; i++) {
		for (int j = i+1; j < 210; j++) {
			if (ok(i, j))
				count++;
		}
	}
	printf("%d\n", count);
}