diff --git a/.gitignore b/.gitignore
index 4917783..238511f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,4 @@ compile_commands.json
.cache
build
.clangd
+cmake-build-*
diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..13566b8
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/advent.iml b/.idea/advent.iml
new file mode 100644
index 0000000..f08604b
--- /dev/null
+++ b/.idea/advent.iml
@@ -0,0 +1,2 @@
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..79b3c94
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..0b5a324
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..f896f2d
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/2015/01.c b/src/2015/01.c
index 05d7e89..c5220be 100644
--- a/src/2015/01.c
+++ b/src/2015/01.c
@@ -1,29 +1,28 @@
#include
#include
-#include
#include "input.h"
void advent2015day01(void) {
- char *input = get_input("input/2015/01");
- char *c = input;
- int f = 0, b = 0, s = 1;
+ char *input = get_input("input/2015/01");
+ char *c = input;
+ int f = 0, b = 0, s = 1;
- while (*c != '\0') {
- if (*c == '(') {
- ++f;
- } else {
- --f;
+ while (*c != '\0') {
+ if (*c == '(') {
+ ++f;
+ } else {
+ --f;
+ }
+
+ if (f == -1 && b == 0) {
+ b = s;
+ }
+
+ ++c;
+ ++s;
}
- if (f == -1 && b == 0) {
- b = s;
- }
-
- ++c;
- ++s;
- }
-
- printf("%d\n%d\n", f, b);
- free(input);
+ printf("%d\n%d\n", f, b);
+ free(input);
}
diff --git a/src/2015/02.c b/src/2015/02.c
index aa7bad2..376a4f5 100644
--- a/src/2015/02.c
+++ b/src/2015/02.c
@@ -6,22 +6,22 @@
#include "advent_math.h"
void advent2015day02(void) {
- size_t sz = 0;
- char **lines = get_lines("input/2015/02", &sz);
- int paper = 0, ribbon = 0;
+ size_t sz = 0;
+ char **lines = get_lines("input/2015/02", &sz);
+ int paper = 0, ribbon = 0;
- for (size_t i = 0; i < sz; i++) {
- char *t = strtok(lines[i], "x");
- int w = atoi(t);
- t = strtok(NULL, "x");
- int l = atoi(t);
- t = strtok(NULL, "x");
- int h = atoi(t);
+ for (size_t i = 0; i < sz; i++) {
+ char *t = strtok(lines[i], "x");
+ int w = atoi(t);
+ t = strtok(NULL, "x");
+ int l = atoi(t);
+ t = strtok(NULL, "x");
+ int h = atoi(t);
- paper += 2*l*w + 2*w*h + 2*h*l + int_min(w*l, int_min(l*h, h*w));
- ribbon += l*w*h + int_min(w+w+h+h, int_min(h+h+l+l, l+l+w+w));
- }
+ paper += 2 * l * w + 2 * w * h + 2 * h * l + int_min(w * l, int_min(l * h, h * w));
+ ribbon += l * w * h + int_min(w + w + h + h, int_min(h + h + l + l, l + l + w + w));
+ }
- printf("%d\n%d\n", paper, ribbon);
- del_lines(lines);
+ printf("%d\n%d\n", paper, ribbon);
+ del_lines(lines);
}
diff --git a/src/2015/03.c b/src/2015/03.c
index e33c5f1..aacbc5e 100644
--- a/src/2015/03.c
+++ b/src/2015/03.c
@@ -1,6 +1,5 @@
#include
#include
-#include
#include "set.h"
#include "input.h"
@@ -11,7 +10,7 @@ static int part_two(char *input) {
int *x, *y;
char *c = input;
- Set* houses = malloc(sizeof(Set));
+ Set *houses = malloc(sizeof(Set));
set_init(houses, same_Point_v, free);
while (*c != '\0') {
@@ -25,16 +24,24 @@ static int part_two(char *input) {
is_santa = is_santa == 1 ? 0 : 1;
switch (*c) {
- case '^': ++(*y); break;
- case 'v': --(*y); break;
- case '>': ++(*x); break;
- case '<': --(*x); break;
+ case '^':
+ ++(*y);
+ break;
+ case 'v':
+ --(*y);
+ break;
+ case '>':
+ ++(*x);
+ break;
+ case '<':
+ --(*x);
+ break;
}
set_insert(houses, (void *) new_Point_p(*x, *y));
++c;
}
- int sz = (int)houses->size;
+ int sz = (int) houses->size;
set_destroy(houses);
return sz;
@@ -44,31 +51,39 @@ static int part_one(char *input) {
int x = 0, y = 0;
char *c = input;
- Set* houses = malloc(sizeof(Set));
+ Set *houses = malloc(sizeof(Set));
set_init(houses, same_Point_v, free);
while (*c != '\0') {
switch (*c) {
- case '^': ++y; break;
- case 'v': --y; break;
- case '>': ++x; break;
- case '<': --x; break;
+ case '^':
+ ++y;
+ break;
+ case 'v':
+ --y;
+ break;
+ case '>':
+ ++x;
+ break;
+ case '<':
+ --x;
+ break;
}
set_insert(houses, (void *) new_Point_p(x, y));
++c;
}
- int sz = (int)houses->size;
+ int sz = (int) houses->size;
set_destroy(houses);
return sz;
}
void advent2015day03(void) {
- char *input = get_input("input/2015/03");
+ char *input = get_input("input/2015/03");
- printf("%d\n", part_one(input));
- printf("%d\n", part_two(input));
+ printf("%d\n", part_one(input));
+ printf("%d\n", part_two(input));
- free(input);
+ free(input);
}
diff --git a/src/2015/04.c b/src/2015/04.c
index 3e5b742..9381c57 100644
--- a/src/2015/04.c
+++ b/src/2015/04.c
@@ -6,46 +6,46 @@
#include "advent_utility.h"
static int is_five(char *test) {
- char *t = test;
- for (int i = 0; i < 5; ++i, ++t) {
- if (*t != '0') {
- return 0;
+ char *t = test;
+ for (int i = 0; i < 5; ++i, ++t) {
+ if (*t != '0') {
+ return 0;
+ }
}
- }
- return 1;
+ return 1;
}
static int is_six(char *test) {
- char *t = test;
- for (int i = 0; i < 6; ++i, ++t) {
- if (*t != '0') {
- return 0;
+ char *t = test;
+ for (int i = 0; i < 6; ++i, ++t) {
+ if (*t != '0') {
+ return 0;
+ }
}
- }
- return 1;
+ return 1;
}
void advent2015day04(void) {
- char *input = get_input("input/2015/04");
- int c = 0, five = 0, six = 0;
+ char *input = get_input("input/2015/04");
+ int c = 0, five = 0, six = 0;
- while (!five || !six) {
- char test[strlen(input) + 8];
- sprintf(test, "%s%d", input, c);
- char *md5 = md5_str(test);
+ while (!five || !six) {
+ char test[strlen(input) + 8];
+ sprintf(test, "%s%d", input, c);
+ char *md5 = md5_str(test);
- if (!five && is_five(md5)) {
- five = c;
- printf("%d\n", five);
- }
- if (is_six(md5)) {
- six = c;
+ if (!five && is_five(md5)) {
+ five = c;
+ printf("%d\n", five);
+ }
+ if (is_six(md5)) {
+ six = c;
+ }
+
+ free(md5);
+ ++c;
}
- free(md5);
- ++c;
- }
-
- printf("%d\n", six);
- free(input);
+ printf("%d\n", six);
+ free(input);
}