diff options
author | Iru Cai <mytbk920423@gmail.com> | 2018-06-26 14:07:24 +0800 |
---|---|---|
committer | Iru Cai <mytbk920423@gmail.com> | 2018-06-26 14:07:24 +0800 |
commit | fba918ba8f244d466d240341abe49a308fbf9156 (patch) | |
tree | 7408c6afa261645d31e2a93b5dac27948024a4f4 /euler90.c | |
parent | 84c0b0d2ddd5b7ef2c9132118485d745aef9d2cf (diff) | |
download | project_euler-fba918ba8f244d466d240341abe49a308fbf9156.tar.xz |
90, 315
Diffstat (limited to 'euler90.c')
-rw-r--r-- | euler90.c | 69 |
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); +} |