diff options
Diffstat (limited to '2023/07')
| -rw-r--r-- | 2023/07/7a.c | 9 | ||||
| -rw-r--r-- | 2023/07/7b.c | 9 |
2 files changed, 6 insertions, 12 deletions
diff --git a/2023/07/7a.c b/2023/07/7a.c index ffc9b5c..7cc4958 100644 --- a/2023/07/7a.c +++ b/2023/07/7a.c | |||
| @@ -11,18 +11,15 @@ int value[255] = { | |||
| 11 | ['T'] = 10, ['J'] = 11, ['Q'] = 12, ['K'] = 13, ['A'] = 14 | 11 | ['T'] = 10, ['J'] = 11, ['Q'] = 12, ['K'] = 13, ['A'] = 14 |
| 12 | }; | 12 | }; |
| 13 | 13 | ||
| 14 | typedef struct { | 14 | typedef struct { char c[5]; int64_t b; } hand_t; |
| 15 | char c[5]; | ||
| 16 | int64_t b; | ||
| 17 | } hand_t; | ||
| 18 | 15 | ||
| 19 | int strength(hand_t h) { | 16 | int strength(hand_t h) { |
| 20 | int i, c2, c1, s, x[15]; | 17 | int i, c2, c1, s, x[15]; |
| 21 | 18 | ||
| 22 | memset(x, 0, 15 * sizeof(int)); | 19 | memset(x, 0, 15 * sizeof(int)); |
| 23 | for (i = 0, s = 0; i < 5; i++) { | 20 | for (i = 0, s = 0; i < 5; i++) { |
| 24 | s = s * 15 + value[h.c[i]]; | 21 | s = s * 15 + value[(int)h.c[i]]; |
| 25 | x[value[h.c[i]]]++; | 22 | x[value[(int)h.c[i]]]++; |
| 26 | } | 23 | } |
| 27 | for (i = 2, c1 = 0, c2 = 0; i < 15; i++) { | 24 | for (i = 2, c1 = 0, c2 = 0; i < 15; i++) { |
| 28 | if (c1 < x[i]) { | 25 | if (c1 < x[i]) { |
diff --git a/2023/07/7b.c b/2023/07/7b.c index 58716b3..be3e9e8 100644 --- a/2023/07/7b.c +++ b/2023/07/7b.c | |||
| @@ -11,18 +11,15 @@ int value[255] = { | |||
| 11 | ['T'] = 10, ['J'] = 1, ['Q'] = 12, ['K'] = 13, ['A'] = 14 | 11 | ['T'] = 10, ['J'] = 1, ['Q'] = 12, ['K'] = 13, ['A'] = 14 |
| 12 | }; | 12 | }; |
| 13 | 13 | ||
| 14 | typedef struct { | 14 | typedef struct { char c[5]; int64_t b; } hand_t; |
| 15 | char c[5]; | ||
| 16 | int64_t b; | ||
| 17 | } hand_t; | ||
| 18 | 15 | ||
| 19 | int strength(hand_t h) { | 16 | int strength(hand_t h) { |
| 20 | int i, c2, c1, s, x[15]; | 17 | int i, c2, c1, s, x[15]; |
| 21 | 18 | ||
| 22 | memset(x, 0, 15 * sizeof(int)); | 19 | memset(x, 0, 15 * sizeof(int)); |
| 23 | for (i = 0, s = 0; i < 5; i++) { | 20 | for (i = 0, s = 0; i < 5; i++) { |
| 24 | s = s * 15 + value[h.c[i]]; | 21 | s = s * 15 + value[(int)h.c[i]]; |
| 25 | x[value[h.c[i]]]++; | 22 | x[value[(int)h.c[i]]]++; |
| 26 | } | 23 | } |
| 27 | for (i = 2, c1 = 0, c2 = 0; i < 15; i++) { | 24 | for (i = 2, c1 = 0, c2 = 0; i < 15; i++) { |
| 28 | if (c1 < x[i]) { | 25 | if (c1 < x[i]) { |
