diff options
author | kartofen <mladenovnasko0@gmail.com> | 2022-12-03 18:16:22 +0200 |
---|---|---|
committer | kartofen <mladenovnasko0@gmail.com> | 2022-12-03 18:16:22 +0200 |
commit | c438b26e7453d890d77c382d8737b74b96f7ac63 (patch) | |
tree | 81839034848299a9bd0a2764aa3f9fd053932e05 | |
parent | 41085185b9a69e455a72d6beed8f29c52967d21d (diff) |
day 3
-rwxr-xr-x | Advent-of-Code-2022/aoc-3/build.sh | 5 | ||||
-rw-r--r-- | Advent-of-Code-2022/aoc-3/input.txt | 300 | ||||
-rw-r--r-- | Advent-of-Code-2022/aoc-3/main.c | 92 | ||||
-rw-r--r-- | Advent-of-Code-2022/aoc-3/sample.txt | 6 | ||||
-rw-r--r-- | Advent-of-Code-2022/aoc-3/vgcore.140079 | bin | 0 -> 6590464 bytes |
5 files changed, 403 insertions, 0 deletions
diff --git a/Advent-of-Code-2022/aoc-3/build.sh b/Advent-of-Code-2022/aoc-3/build.sh new file mode 100755 index 0000000..30f495e --- /dev/null +++ b/Advent-of-Code-2022/aoc-3/build.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +set -xe + +gcc -o main main.c -Wall -Wextra -pedantic diff --git a/Advent-of-Code-2022/aoc-3/input.txt b/Advent-of-Code-2022/aoc-3/input.txt new file mode 100644 index 0000000..51d8036 --- /dev/null +++ b/Advent-of-Code-2022/aoc-3/input.txt @@ -0,0 +1,300 @@ +lvcNpRHDCnTLCJlL +RFZggsMrjTFGCJmdmd +srsBZgBqwBqRZbzqtHpzzDNtHDqV +CCTPpCvlpzzZQQQflrzbQDttTJcgcggJcHtcddtdhT +nMLBRnGsFFLznRFRLMMNBnNLDRDdhScJccctdSccJJgDDHhH +GVBGVBsLjsrrvfzpjpfQ +dzVRSPVVBVDSPzDBQVSQFFlrclMplpMJMtPJlJvHZCMt +TjmGmbhjTnTmwhmrvvrHcZvCHZMl +fnLwwqfwfqjghHwGThwfTGGBFVDFFsszSRVzRBsdBDgFsV +CCWFCcdDWwcWFp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gfDFmmfFpcVzMzqZZzcCPQVZzqP +SmgtSjGPjppBjbqqWTCZDQTHHHTg +VsFfCzLvsMfzNfNRhVMslzlHqrWrQDQcqDqTrLWHcrWJJW +dsRdsNCvNMVpwPdnnGbbPb diff --git a/Advent-of-Code-2022/aoc-3/main.c b/Advent-of-Code-2022/aoc-3/main.c new file mode 100644 index 0000000..d8e5815 --- /dev/null +++ b/Advent-of-Code-2022/aoc-3/main.c @@ -0,0 +1,92 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#if 0 + #define PART part1 +#else + #define PART part2 +#endif + +#if 0 + #define FILENAME "sample.txt" +#else + #define FILENAME "input.txt" +#endif + +int sum = 0; + +int char_to_index(char ch) +{ + if(ch >= 'a') + return ch - 'a'; + return ch - 'A' + 26; +} + +void part1(char *line) +{ + int times_seen[56] = {0}; + int leftest[56] = {0}; // rightest position of that character seen + int rightest[56] = {0}; // leftest position of that character seen + + int len = strlen(line); + len = (len % 2) ? len : len - 1; // fgets reads the new line and the last line has no newline + for(int i = 0; i < len; i++) + { + int ch = char_to_index(line[i]); + times_seen[ch]++; + if(times_seen[ch] == 1) + leftest[ch] = i; + else + rightest[ch] = i; + + if(times_seen[ch] > 1) + if(leftest[ch] < len/2 && rightest[ch] >= len/2) { + sum += ch + 1; + break; + } + } +} + +int gn = 0; +int times_seen[56][3] = {0}; + +void part2(char *line) +{ + for(int i = 0; line[i] != '\n' && line[i] != '\0'; i++) + times_seen[char_to_index(line[i])][gn]++; + gn++; + + if(gn == 3) { + for(int j = 0; j < 56; j++) + if(times_seen[j][0] && times_seen[j][1] && times_seen[j][2]) { + sum += j + 1; + break; + } + gn = 0; + memset(times_seen, 0, sizeof(times_seen)); + } + +} + +void parse() +{ + FILE *fp = fopen(FILENAME, "r"); + if(!fp) { + fprintf(stderr, "ERROR: Could not open file: %s\n", FILENAME); + exit(1); + } + + char line[256]; + while(fgets(line, sizeof(line), fp) != NULL) + PART(line); + + fclose(fp); +} + +int main(void) +{ + parse(); + printf("%d\n", sum); + return 0; +} diff --git a/Advent-of-Code-2022/aoc-3/sample.txt b/Advent-of-Code-2022/aoc-3/sample.txt new file mode 100644 index 0000000..f17e726 --- /dev/null +++ b/Advent-of-Code-2022/aoc-3/sample.txt @@ -0,0 +1,6 @@ +vJrwpWtwJgWrhcsFMMfFFhFp +jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL +PmmdzqPrVvPwwTWBwg +wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn +ttgJtRGJQctTZtZT +CrZsJsPPZsGzwwsLwLmpwMDw diff --git a/Advent-of-Code-2022/aoc-3/vgcore.140079 b/Advent-of-Code-2022/aoc-3/vgcore.140079 Binary files differnew file mode 100644 index 0000000..c9dfe3d --- /dev/null +++ b/Advent-of-Code-2022/aoc-3/vgcore.140079 |