-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday_seven.c
53 lines (47 loc) · 1.02 KB
/
day_seven.c
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
#include <stdio.h>
#include <stdlib.h>
#include "string_utilities.h"
typedef struct {
char cards[5];
int bid;
} hand;
const int card_priorities[] = { '1', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A' };
void read_hands(char *input, int len, hand hands[len]) {
int row = 0;
while (row < len) {
hand h;
// read cards
for (int i = 0; i < 5; i++) {
h.cards[i] = *input;
input++;
}
// collect bid
h.bid = atoi(input);
hands[row] = h;
row++;
input = skip_to_tokens(input,"\n");
input++;
}
}
int part_a(char *content) {
int total_hands = count_string_token(content, '\n');
printf("Hands: %d\n", total_hands);
return 0;
}
int part_b(char *content) {
return 0;
}
int main(int argc, char **argv) {
char *contents;
if (argc > 2) {
contents = string_from_file(argv[2]);
} else {
contents = string_from_file("day07ex.txt");
}
if (argc > 1 && argv[1][0] == 'b') {
printf("B Total: %d\n", part_b(contents));
} else {
printf("A Total: %d\n", part_a(contents));
}
free(contents);
}