summaryrefslogtreecommitdiff
path: root/8/part1.c
diff options
context:
space:
mode:
authorBond_009 <bond.009@outlook.com>2022-12-01 22:30:22 +0100
committerBond_009 <bond.009@outlook.com>2022-12-01 22:30:22 +0100
commitbaf4910870a6e8999802b9a4a22eabd4142a34e3 (patch)
tree2d11443dc21e53bd0d99d015cf789937d6d95862 /8/part1.c
parent49d0c908f24b2c193c9deed1716fe36061ba26a1 (diff)
Move all Advent of Codes into one repo
Diffstat (limited to '8/part1.c')
-rw-r--r--8/part1.c74
1 files changed, 0 insertions, 74 deletions
diff --git a/8/part1.c b/8/part1.c
deleted file mode 100644
index d4261be..0000000
--- a/8/part1.c
+++ /dev/null
@@ -1,74 +0,0 @@
-#include <stdio.h>
-#include <stdint.h>
-#include <stdlib.h>
-
-#define INPUT_LEN 650
-
-struct Operation
-{
- char opcode;
- int arg;
- char has_been_executed;
-};
-
-int exe_program(const char *filename)
-{
- FILE *file = fopen(filename, "r");
-
- // Include space for newline and string terminator
- char buffer[16] = { 0 };
-
- struct Operation ops[INPUT_LEN];
- size_t opcount = 0;
-
- while (fgets(buffer, 16, file)) {
- struct Operation *op = &ops[opcount++];
- op->has_been_executed = 0;
- switch (buffer[0])
- {
- // nop
- case 'n':
- op->opcode = 0;
- break;
- // acc
- case 'a':
- op->opcode = 1;
- break;
- // jmp
- case 'j':
- op->opcode = 2;
- break;
- }
-
- op->arg = atoi(&buffer[4]);
- }
-
- fclose(file);
-
- struct Operation *cur_op = ops;
- int acc = 0;
- while (!cur_op->has_been_executed)
- {
- cur_op->has_been_executed = 1;
- switch (cur_op->opcode)
- {
- case 0:
- cur_op++;
- break;
- case 1:
- acc += cur_op->arg;
- cur_op++;
- break;
- case 2:
- cur_op += cur_op->arg;
- break;
- }
- }
-
- return acc;
-}
-
-int main(int argc, char *argv[])
-{
- printf("%i\n", exe_program(argv[argc - 1]));
-}