summaryrefslogtreecommitdiff
path: root/euler90.c
diff options
context:
space:
mode:
Diffstat (limited to 'euler90.c')
-rw-r--r--euler90.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/euler90.c b/euler90.c
new file mode 100644
index 0000000..b514269
--- /dev/null
+++ b/euler90.c
@@ -0,0 +1,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);
+}