summaryrefslogtreecommitdiff
path: root/6.c
diff options
context:
space:
mode:
Diffstat (limited to '6.c')
-rw-r--r--6.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/6.c b/6.c
new file mode 100644
index 0000000..8476b74
--- /dev/null
+++ b/6.c
@@ -0,0 +1,69 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#define MAX_BOARDS 100
+
+static char *ReadLine(char *p, size_t size, FILE *fp)
+{
+ if ((p=fgets(p, size, fp)))
+ {
+ size_t l = strlen(p);
+
+ while(l && p[l-1] == '\n')
+ {
+ p[--l] = 0;
+ }
+ }
+
+ return p;
+}
+
+int main(void)
+{
+ char buff[1024];
+ int *num = NULL;
+ int num_count = 0;
+ char *p = NULL;
+ int f = 0;
+ int cycle = 0;
+
+ ReadLine(buff, sizeof buff, stdin);
+
+ p = strtok(buff, ",");
+
+ while(p)
+ {
+ num = realloc(num, (num_count + 1) * sizeof *num);
+ num[num_count++] = atoi(p);
+ p = strtok(NULL, ",");
+ }
+
+ for(cycle = 0; cycle < 80; cycle++)
+ {
+ int to_add = 0;
+
+ for(f = 0; f < num_count; f++)
+ {
+ if (num[f] == 0)
+ {
+ to_add++;
+ num[f] = 6;
+ }
+ else
+ {
+ num[f]--;
+ }
+ }
+
+ for(f = 0; f < to_add; f++)
+ {
+ num = realloc(num, (num_count + 1) * sizeof *num);
+ num[num_count++] = 8;
+ }
+ }
+
+ printf("num_count=%d\n", num_count);
+
+ return 0;
+}