diff options
author | kartofen <mladenovnasko0@gmail.com> | 2022-07-31 11:55:45 +0300 |
---|---|---|
committer | kartofen <mladenovnasko0@gmail.com> | 2022-07-31 11:55:45 +0300 |
commit | 48966f12832ac97228132e56fb3159099f3e466e (patch) | |
tree | 9cc37aab6d00230787e19b68127abd2b818068ef /Advent-of-Code-2021/AOC-3/aoc-3.c | |
parent | aec1c07260257ba7c28eff53f422ddb7daaf316a (diff) |
cleanup
Diffstat (limited to 'Advent-of-Code-2021/AOC-3/aoc-3.c')
-rw-r--r-- | Advent-of-Code-2021/AOC-3/aoc-3.c | 86 |
1 files changed, 0 insertions, 86 deletions
diff --git a/Advent-of-Code-2021/AOC-3/aoc-3.c b/Advent-of-Code-2021/AOC-3/aoc-3.c deleted file mode 100644 index 51cab24..0000000 --- a/Advent-of-Code-2021/AOC-3/aoc-3.c +++ /dev/null @@ -1,86 +0,0 @@ -#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; - } - - fclose(fp); -} - -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; -} |