summaryrefslogtreecommitdiff
path: root/2022/day03/main2.c
diff options
context:
space:
mode:
authorOrangerot <purple@orangerot.dev>2022-12-17 01:16:18 +0100
committerOrangerot <purple@orangerot.dev>2022-12-17 01:16:18 +0100
commit6596b48113ced669b206d2e1f1e8ba6edcba88a2 (patch)
tree02c7d01783390862d989df6c91aff968e03dd415 /2022/day03/main2.c
adv2022 first 8 days
Diffstat (limited to '2022/day03/main2.c')
-rw-r--r--2022/day03/main2.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/2022/day03/main2.c b/2022/day03/main2.c
new file mode 100644
index 0000000..17daa38
--- /dev/null
+++ b/2022/day03/main2.c
@@ -0,0 +1,45 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+char getWrong(char *line, char *line2, char *line3)
+{
+
+ for (char *a = line; *a != '\n'; a++)
+ {
+ for (char *b = line2; *b != '\n'; b++)
+ {
+ for (char *c = line3; *c != '\n'; c++)
+ {
+ if ( *a == *b && *a == *c ) return *b;
+ }
+ }
+ }
+}
+
+int main()
+{
+ char *line = NULL;
+ char *line2 = NULL;
+ char *line3 = NULL;
+ size_t len;
+ size_t len2;
+ size_t len3;
+ int prios = 0;
+
+ while (getline(&line, &len, stdin) >= 0)
+ {
+ getline(&line2, &len2, stdin);
+ getline(&line3, &len3, stdin);
+
+ char wrong = getWrong(line, line2, line3);
+ 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);
+}
+