summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kikoodx@paranoici.org>2023-12-10 06:15:46 +0100
committerkdx <kikoodx@paranoici.org>2023-12-10 06:15:46 +0100
commitc538a38566d9d5c5e4eeeb3469e208a40fe8d3b4 (patch)
tree8dec3d09c9d75241c8e3643d9eb484cc004d81e5
parentfc51b15375344a73cb835c98e2fb7ae04dafbf44 (diff)
downloadaoc23-c538a38566d9d5c5e4eeeb3469e208a40fe8d3b4.tar.gz
10
-rw-r--r--10/_.h39
-rwxr-xr-x10/build.sh2
-rwxr-xr-x10/commit.sh3
-rw-r--r--10/compile_flags.txt4
-rw-r--r--10/main.cpp50
-rwxr-xr-x10/submit.sh6
-rwxr-xr-x10/test.sh2
7 files changed, 106 insertions, 0 deletions
diff --git a/10/_.h b/10/_.h
new file mode 100644
index 0000000..1777a0c
--- /dev/null
+++ b/10/_.h
@@ -0,0 +1,39 @@
+#pragma once
+#include <string>
+#include <iostream>
+#include <vector>
+using namespace std;
+
+void print(auto v) {
+ cout << v << endl;
+}
+
+vector<string>
+split(string str, const string &sep, bool ignore_empty = true)
+{
+ vector<string> vec;
+
+ bool end_sep = (sep.length() <= str.length() &&
+ str.substr(str.length() - sep.length()) == sep);
+
+ for (;;) {
+ const size_t find = str.find(sep);
+ if (find == string::npos) {
+ break;
+ }
+ string const bit = str.substr(0, find);
+ if (!ignore_empty || !bit.empty()) {
+ vec.push_back(bit);
+ }
+ str.erase(0, find + sep.length());
+ }
+
+ if (!str.empty()) {
+ vec.push_back(str);
+ }
+ if (!ignore_empty && end_sep) {
+ vec.push_back("");
+ }
+ return vec;
+}
+
diff --git a/10/build.sh b/10/build.sh
new file mode 100755
index 0000000..fe67df4
--- /dev/null
+++ b/10/build.sh
@@ -0,0 +1,2 @@
+#!/bin/sh
+g++ -std=c++20 -Wall -Wextra -include_.h *.cpp
diff --git a/10/commit.sh b/10/commit.sh
new file mode 100755
index 0000000..4daa1c6
--- /dev/null
+++ b/10/commit.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+git add .
+git commit -m "$(basename $(pwd))"
diff --git a/10/compile_flags.txt b/10/compile_flags.txt
new file mode 100644
index 0000000..9e4630a
--- /dev/null
+++ b/10/compile_flags.txt
@@ -0,0 +1,4 @@
+-std=c++20
+-Wall
+-Wextra
+-include_.h
diff --git a/10/main.cpp b/10/main.cpp
new file mode 100644
index 0000000..fa386b1
--- /dev/null
+++ b/10/main.cpp
@@ -0,0 +1,50 @@
+#include <assert.h>
+
+struct Point { int x, y; };
+
+Point start;
+vector<string> grid{};
+
+int loop_traverse(int x, int y, int dx, int dy) {
+ x += dx;
+ y += dy;
+ if (x == start.x && y == start.y)
+ return 1;
+ switch (grid[y][x]) {
+ case '-':
+ case '|':
+ return 1 + loop_traverse(x, y, dx, dy);
+ case '7':
+ case 'L':
+ return 1 + loop_traverse(x, y, dy, dx);
+ case 'F':
+ case 'J':
+ return 1 + loop_traverse(x, y, -dy, -dx);
+ default:
+ assert(0);
+ }
+}
+
+int main() {
+ string line;
+
+ while (getline(cin, line))
+ grid.push_back(line);
+
+ unsigned x, y;
+ for (y = 0; y < grid.size(); y++) {
+ for (x = 0; x < grid[y].length(); x++) {
+ if (grid[y][x] == 'S')
+ goto found;
+ }
+ }
+ found:;
+
+ start.x = x;
+ start.y = y;
+ grid[start.y][start.x] = 'F';
+
+ print(loop_traverse(start.x, start.y, 1, 0) / 2);
+
+ return 0;
+}
diff --git a/10/submit.sh b/10/submit.sh
new file mode 100755
index 0000000..116caff
--- /dev/null
+++ b/10/submit.sh
@@ -0,0 +1,6 @@
+#!/bin/sh
+PART="$2"
+ARG="$1"
+test "$ARG" == "" && ARG="$(wl-paste)"
+test "$PART" == "" && PART="1"
+aoc -y 2023 -d "$(basename $(pwd))" submit "$PART" "$ARG"
diff --git a/10/test.sh b/10/test.sh
new file mode 100755
index 0000000..2fdcb42
--- /dev/null
+++ b/10/test.sh
@@ -0,0 +1,2 @@
+#!/bin/sh
+./build.sh && ./a.out <input