summaryrefslogtreecommitdiff
path: root/Advent-of-Code-2021/AOC-3/aoc-3.c~
diff options
context:
space:
mode:
Diffstat (limited to 'Advent-of-Code-2021/AOC-3/aoc-3.c~')
-rw-r--r--Advent-of-Code-2021/AOC-3/aoc-3.c~84
1 files changed, 84 insertions, 0 deletions
diff --git a/Advent-of-Code-2021/AOC-3/aoc-3.c~ b/Advent-of-Code-2021/AOC-3/aoc-3.c~
new file mode 100644
index 0000000..936402f
--- /dev/null
+++ b/Advent-of-Code-2021/AOC-3/aoc-3.c~
@@ -0,0 +1,84 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <stdint.h>
+
+#define N 5
+#define INP_COUNT 12
+
+int table[N];
+
+void ParseInput(char *filepath)
+{
+ char ch;
+ FILE *fp;
+ fp = fopen(filepath, "r");
+
+ if(fp == NULL)
+ {
+ fprintf(stderr, "ERROR: something with file idk what fuck you");
+ exit(EXIT_FAILURE);
+ }
+
+ int i = 0;
+ while((ch = fgetc(fp)) != EOF)
+ {
+ if(ch == '\n') { i = 0; continue; }
+
+ if(ch == '1')
+ table[i] += 1;
+
+ i += 1;
+ }
+}
+
+void PrintTable()
+{
+ for(int i=0; i<N; i++)
+ {
+ printf("bitplace %d: %d\n", i+1, table[i]);
+ }
+}
+
+int PartOne()
+{
+ int gamma_val = 0;
+ for(int i=0; i<N; i++)
+ {
+ assert(table[i] != (INP_COUNT/2));
+
+ if(table[i] > (INP_COUNT/2))
+ {
+ gamma_val = gamma_val | (1 << (N-1-i));
+ }
+ }
+
+ int epsilon_val = gamma_val;
+ for(int i=0; i<N; i++)
+ {
+ epsilon_val = epsilon_val ^ (1 << i);
+ }
+
+ int result = gamma_val * epsilon_val;
+ return result;
+}
+
+int PartTwo()
+{
+
+
+ int result = 0;
+ return result;
+}
+
+int main(void)
+{
+ memset(table, 0, sizeof(int)*N);
+ ParseInput("sample.txt");
+
+ PrintTable();
+ printf("Part 1-RESULT: %d\n", PartOne());
+
+ return 0;
+}