diff options
Diffstat (limited to '6a.c')
-rw-r--r-- | 6a.c | 56 |
1 files changed, 11 insertions, 45 deletions
@@ -2,14 +2,7 @@ #include <stdio.h> #include <string.h> -typedef struct node -{ - struct node *next; - int i; -} node; - -static node *head = NULL; -static node *tail = NULL; +#define MAX_BOARDS 100 static char *ReadLine(char *p, size_t size, FILE *fp) { @@ -26,32 +19,10 @@ static char *ReadLine(char *p, size_t size, FILE *fp) return p; } -static void Add(int i) -{ - node *new; - - new = malloc(sizeof *new); - - new->next = NULL; - - if (tail) - { - tail->next = new; - } - - tail = new; - - if (!head) - { - head = new; - } - - new->i = i; -} - int main(void) { char buff[1024]; + char *num = NULL; unsigned long long num_count = 0; char *p = NULL; unsigned long long f = 0; @@ -63,43 +34,38 @@ int main(void) while(p) { - Add(atoi(p)); + num = realloc(num, (num_count + 1) * sizeof *num); + num[num_count++] = atoi(p); p = strtok(NULL, ","); } for(cycle = 0; cycle < 256; cycle++) { int to_add = 0; - node *list; - - list = head; - while(list) + for(f = 0; f < num_count; f++) { - if (list->i == 0) + if (num[f] == 0) { to_add++; - list->i = 6; + num[f] = 6; } else { - list->i--; + num[f]--; } - - list = list->next; } if (to_add) { - num_count += to_add; - + num = realloc(num, (num_count + to_add) * sizeof *num); for(f = 0; f < to_add; f++) { - Add(8); + num[num_count++] = 8; } } - printf("cycle %d/%llu\n", cycle, num_count); + printf("cycle/num_count = %d/%llu\n", cycle, num_count); } printf("num_count=%llu\n", num_count); |