aboutsummaryrefslogtreecommitdiff
path: root/advent-of-code/2022/10
diff options
context:
space:
mode:
Diffstat (limited to 'advent-of-code/2022/10')
-rw-r--r--advent-of-code/2022/10/1.c54
-rw-r--r--advent-of-code/2022/10/2.c62
-rw-r--r--advent-of-code/2022/10/Makefile12
-rw-r--r--advent-of-code/2022/10/input141
4 files changed, 0 insertions, 269 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;
-}
diff --git a/advent-of-code/2022/10/2.c b/advent-of-code/2022/10/2.c
deleted file mode 100644
index 1abcb7e..0000000
--- a/advent-of-code/2022/10/2.c
+++ /dev/null
@@ -1,62 +0,0 @@
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <stdbool.h>
-
-#include <str.h>
-
-char screen[6][40];
-
-int regx = 0;
-int time = 0;
-
-void process() {
- if (time >= 240) return;
- int delta = time % 40 - regx;
- if (delta <= 2 && delta >= 0) {
- screen[time / 40][time % 40] = '#';
- }
-}
-
-void tick(int value) {
- process();
- time++;
- regx += value;
-}
-
-int main() {
- memset(screen, '.', 240);
- 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);
- }
- for (int i = 0; i < 6; i++) {
- for (int j = 0; j < 40; j++) {
- printf("%c", screen[i][j]);
- }
- printf("\n");
- }
- return 0;
-}
diff --git a/advent-of-code/2022/10/Makefile b/advent-of-code/2022/10/Makefile
deleted file mode 100644
index baa0901..0000000
--- a/advent-of-code/2022/10/Makefile
+++ /dev/null
@@ -1,12 +0,0 @@
-all: 1.out 2.out
-LIB=../lib/str.c
-
-1.out: 1.c
- cc -g -I../lib/ $< $(LIB) -o $@
-
-2.out: 2.c
- cc -g -I../lib/ $< $(LIB) -o $@
-
-.PHONY: clean
-clean:
- -rm *.out
diff --git a/advent-of-code/2022/10/input b/advent-of-code/2022/10/input
deleted file mode 100644
index 0464ea6..0000000
--- a/advent-of-code/2022/10/input
+++ /dev/null
@@ -1,141 +0,0 @@
-noop
-addx 25
-addx -5
-addx -14
-addx 4
-noop
-addx 2
-addx 3
-noop
-noop
-noop
-noop
-addx 3
-addx 5
-addx 2
-noop
-noop
-addx 5
-noop
-noop
-noop
-addx 1
-addx 2
-addx 5
-addx -40
-addx 5
-noop
-addx 26
-addx -20
-addx -3
-addx 2
-noop
-addx -4
-addx 9
-addx 5
-addx 2
-addx 11
-addx -10
-addx 2
-addx 5
-addx 2
-addx 5
-noop
-noop
-noop
-addx -31
-addx 32
-addx -37
-addx 1
-addx 8
-addx 13
-addx -15
-addx 4
-noop
-addx 5
-noop
-addx 3
-addx -2
-addx 4
-addx 1
-addx 4
-addx -14
-addx 15
-addx 4
-noop
-noop
-noop
-addx 3
-addx 5
-addx -40
-noop
-addx 5
-addx 8
-addx -3
-noop
-addx 2
-addx 9
-addx -4
-noop
-noop
-noop
-noop
-addx 5
-addx -9
-addx 10
-addx 4
-noop
-noop
-addx 5
-addx -19
-addx 24
-addx -2
-addx 5
-addx -40
-addx 22
-addx -19
-addx 2
-addx 5
-addx 2
-addx 5
-noop
-noop
-addx -2
-addx 2
-addx 5
-addx 3
-noop
-addx 2
-addx 2
-addx 3
-addx -2
-addx 10
-addx -3
-addx 3
-noop
-addx -40
-addx 2
-addx 11
-addx -5
-addx -1
-noop
-addx 3
-addx 7
-noop
-addx -2
-addx 5
-addx 2
-addx 3
-noop
-addx 2
-addx 6
-addx -5
-addx 2
-addx -18
-addx 26
-addx -1
-noop
-noop
-noop
-noop
-