summaryrefslogtreecommitdiff
path: root/13/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 /13/part1.c
parent49d0c908f24b2c193c9deed1716fe36061ba26a1 (diff)
Move all Advent of Codes into one repo
Diffstat (limited to '13/part1.c')
-rw-r--r--13/part1.c48
1 files changed, 0 insertions, 48 deletions
diff --git a/13/part1.c b/13/part1.c
deleted file mode 100644
index b62d007..0000000
--- a/13/part1.c
+++ /dev/null
@@ -1,48 +0,0 @@
-#include <stdio.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
-
-#define BUFFER_SIZE 256
-#define MAX_INPUT_LEN 128
-
-int solve(const char *filename)
-{
- FILE *file = fopen(filename, "r");
-
- char buffer[BUFFER_SIZE] = { 0 };
- fgets(buffer, BUFFER_SIZE, file);
- int depart = atoi(buffer);
- fgets(buffer, BUFFER_SIZE, file);
- int bus_ids[MAX_INPUT_LEN] = { 0 };
- bus_ids[0] = atoi(buffer);
- int i = 1;
- char *p = buffer;
- while ((p = strchr(p, ','))) {
- // x is never the last value, just keep looping we find a valid input
- while (*++p == 'x') {
- p += 1;
- }
-
- bus_ids[i++] = atoi(p);
- }
-
- int bus_id = 0;
- int wait = INT32_MAX;
- for (int j = 0; j < i; j++) {
- int id = bus_ids[j];
- int tmprem = id - (depart % id);
- if (tmprem < wait) {
- bus_id = id;
- wait = tmprem;
- }
- }
-
- fclose(file);
- return bus_id * wait;
-}
-
-int main(int argc, char *argv[])
-{
- printf("%i\n", solve(argv[argc - 1]));
-}