aboutsummaryrefslogtreecommitdiff
path: root/advent-of-code/2022/10/1.c
diff options
context:
space:
mode:
authorMistivia <i@mistivia.com>2024-02-16 11:11:14 +0800
committerMistivia <i@mistivia.com>2024-02-16 11:11:14 +0800
commit050fa7cbfb6b7cf293fb02e06daf123b3e6af816 (patch)
treeb547869fabbbf1f1153098ef811398ed40485d0a /advent-of-code/2022/10/1.c
parente1a5304af2c35ff83819546953309764e24656d4 (diff)
delete advent of code 2022
Diffstat (limited to 'advent-of-code/2022/10/1.c')
-rw-r--r--advent-of-code/2022/10/1.c54
1 files changed, 0 insertions, 54 deletions
diff --git a/advent-of-code/2022/10/1.c b/advent-of-code/2022/10/1.c
deleted file mode 100644
index 12ddc22..0000000
--- a/advent-of-code/2022/10/1.c
+++ /dev/null
@@ -1,54 +0,0 @@
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <stdbool.h>
-
-#include <str.h>
-
-int strength = 1;
-int sum = 0;
-int time = 1;
-
-int process() {
- if (time == 20 || time == 60 || time == 100
- || time == 140 || time == 180 || time == 220) {
- sum += strength * time;
- }
-}
-
-void tick(int value) {
- process();
- time++;
- strength += value;
-}
-
-int main() {
- FILE *fp = fopen("input", "r");
- while (true) {
- char *rawline = fgetline(fp);
- if (rawline == NULL) break;
- char *line = str_strip(rawline);
- free(rawline);
- char** words = str_split(line, ' ');
- if (words == NULL) {
- free(line);
- continue;
- }
- if (words[0] == NULL) {
- free(line); free(words);
- continue;
- }
- if (strcmp(words[0], "noop") == 0) {
- tick(0);
- } else if (strcmp(words[0], "addx") == 0) {
- tick(0);
- char *ptr;
- int value = strtol(words[1], &ptr, 10);
- tick(value);
- }
- str_list_free(words);
- free(line);
- }
- printf("%d\n", sum);
- return 0;
-}