summaryrefslogtreecommitdiff
path: root/2022/day03/main.c
diff options
context:
space:
mode:
Diffstat (limited to '2022/day03/main.c')
-rw-r--r--2022/day03/main.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/2022/day03/main.c b/2022/day03/main.c
new file mode 100644
index 0000000..69068fa
--- /dev/null
+++ b/2022/day03/main.c
@@ -0,0 +1,36 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+char getWrong(char *line)
+{
+ char *middle = line + strlen(line)/2;
+ char *a = line;
+ char *b = middle;
+ for (char *a = line; a < middle; a++)
+ {
+ for (char *b = middle; *b != '\n'; b++)
+ {
+ if ( *a == *b ) return *b;
+ }
+ }
+}
+
+int main()
+{
+ char *line = NULL;
+ size_t len;
+ int prios = 0;
+
+ while (getline(&line, &len, stdin) >= 0)
+ {
+ char wrong = getWrong(line);
+ printf("%c", wrong);
+ int prio;
+ if ( wrong >= 97 && wrong <= 122 ) prio = wrong - 96;
+ else prio = wrong - 64 + 26;
+ printf("%d", prio);
+ prios += prio;
+ }
+ printf("\n%d\n", prios);
+}