summaryrefslogtreecommitdiff
path: root/8.c
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2021-12-09 23:50:11 +0000
committerIan C <ianc@noddybox.co.uk>2021-12-09 23:50:11 +0000
commitc52a19c71cf16346c5de5e21425063047311b786 (patch)
tree2ae3b42e8f4620e549b1d966ebc0d5e9aa1de95b /8.c
parent1dfae1e03aee84b73d0114dfa16d827373ea6ce7 (diff)
Added day 8. Part 2 doesn't work.
Diffstat (limited to '8.c')
-rw-r--r--8.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/8.c b/8.c
new file mode 100644
index 0000000..c0bf7c5
--- /dev/null
+++ b/8.c
@@ -0,0 +1,53 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+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[0x8000];
+ char *signal[10] = {0};
+ char *digit[4] = {0};
+ int sum = 0;
+ int f = 0;
+
+ while(ReadLine(buff, sizeof buff, stdin))
+ {
+ for(f = 0; f < 10; f++)
+ {
+ signal[f] = strtok(f == 0 ? buff : NULL, " |");
+ }
+
+ for(f = 0; f < 4; f++)
+ {
+ size_t len;
+
+ digit[f] = strtok(NULL, " |");
+
+ len = strlen(digit[f]);
+
+ if (len == 2 || len == 4 || len == 3 || len == 7)
+ {
+ sum++;
+ }
+ }
+ }
+
+ printf("sum = %d\n", sum);
+
+ return 0;
+}