From 0800c967f1f6f84ffca5b419f4766edb4a98e4c8 Mon Sep 17 00:00:00 2001 From: laura Date: Fri, 12 Dec 2025 16:25:54 +0100 Subject: [PATCH] solved day 6 part 1 --- 6/Makefile | 13 +++++++ 6/main.c | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+) create mode 100644 6/Makefile create mode 100644 6/main.c diff --git a/6/Makefile b/6/Makefile new file mode 100644 index 0000000..ba44bd3 --- /dev/null +++ b/6/Makefile @@ -0,0 +1,13 @@ +client: main.c + gcc -o main main.c -O3 -Wall -Wextra -g -march=x86-64-v3 + +client-debug: main.c + gcc -o main main.c -O1 -Wall -Wextra -g -fsanitize=address + +client-debug-nosanitize: main.c + gcc -o main main.c -O1 -Wall -Wextra -g + +clean: + rm main + +.PHONY: clean \ No newline at end of file diff --git a/6/main.c b/6/main.c new file mode 100644 index 0000000..d0e5280 --- /dev/null +++ b/6/main.c @@ -0,0 +1,105 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +char input[] = +{ +#embed "input.txt" +,'\0' // null terminator +}; + +int width = 0; +int height = 0; +uint64_t result = 0; + + +uint64_t parseNum(char* str){ + int i = 0; + while(str[i] == ' '){ + i++; + } + uint64_t out = 0; + while(str[i] != ' ' && str[i] != '\n'){ + //printf("%c", str[i]); + out += str[i]-0x30; + out *= 10; + i++; + } + out /=10; + return out; +} + +int main(int argc, char *argv[]){ + clock_t start, end; + start = clock(); + + + while(input[width] != '\n'){ + width++; + } + + printf("width: %d\n", width); + //parse ranges first + int i = 0; + int lines = 0; + while(input[i+1] != 0){ + lines++; + i+=(width+1); + } + + + char* symbols = input+(width+1)*(lines-1); + printf("line count: %d\n", lines); + printf("symbols:\n%s\n", symbols); + + printf("parsing the first number: %lu\n", parseNum(input+8)); + + + int parse_length = 1; + uint64_t col_res; + while(*symbols != 0){ + while(symbols[parse_length] == ' ' || symbols[parse_length] == '\n'){ + parse_length++; + } + parse_length--; + printf("parsing %d long numbers\n", parse_length); + + if(*symbols == '*'){ + col_res = 1; + printf("multiplying....\n"); + for(int i = 1; i