summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kikoodx@paranoici.org>2023-12-12 06:56:11 +0100
committerkdx <kikoodx@paranoici.org>2023-12-12 06:56:11 +0100
commit367254b29a39552ef3c318240958d094dc76d5b8 (patch)
treef0b3d1180b97e62d9ab0916121eeb80e09b751e3
parentc56c72fa331716005144c1ea6d43123571bb2068 (diff)
downloadaoc23-main.tar.gz
12 i'm fuckedHEADmain
-rw-r--r--12/_.h39
-rwxr-xr-x12/build.sh2
-rwxr-xr-x12/commit.sh3
-rw-r--r--12/compile_flags.txt4
-rw-r--r--12/main.cpp71
-rwxr-xr-x12/submit.sh6
-rwxr-xr-x12/test.sh2
7 files changed, 127 insertions, 0 deletions
diff --git a/12/_.h b/12/_.h
new file mode 100644
index 0000000..1777a0c
--- /dev/null
+++ b/12/_.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/12/build.sh b/12/build.sh
new file mode 100755
index 0000000..fe67df4
--- /dev/null
+++ b/12/build.sh
@@ -0,0 +1,2 @@
+#!/bin/sh
+g++ -std=c++20 -Wall -Wextra -include_.h *.cpp
diff --git a/12/commit.sh b/12/commit.sh
new file mode 100755
index 0000000..4daa1c6
--- /dev/null
+++ b/12/commit.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+git add .
+git commit -m "$(basename $(pwd))"
diff --git a/12/compile_flags.txt b/12/compile_flags.txt
new file mode 100644
index 0000000..9e4630a
--- /dev/null
+++ b/12/compile_flags.txt
@@ -0,0 +1,4 @@
+-std=c++20
+-Wall
+-Wextra
+-include_.h
diff --git a/12/main.cpp b/12/main.cpp
new file mode 100644
index 0000000..4503bd4
--- /dev/null
+++ b/12/main.cpp
@@ -0,0 +1,71 @@
+static long check(string map, const vector<int>& seq) {
+ unsigned i = 0;
+ for (auto& c : map)
+ if (c == '?')
+ c = '.';
+ for (auto e : seq) {
+ while (i < map.length() && map[i] != '#')
+ i += 1;
+ if (map[i] != '#')
+ goto invalid;
+ for (auto k = 0; k < e; k++) {
+ if (map[i] != '#')
+ goto invalid;
+ i += 1;
+ }
+ if (i < map.length() && map[i] == '#')
+ goto invalid;
+ }
+ print(map);
+ return 1;
+invalid:
+ return 0;
+}
+
+static long recurse(string& map, const vector<int>& seq, unsigned count, unsigned depth, unsigned i) {
+ long sum = 0;
+ while (i < map.length()) {
+ if (map[i] != '?') {
+ i++;
+ continue;
+ }
+ map[i] = '#';
+ if (depth < count)
+ sum += recurse(map, seq, count, depth + 1, i + 1);
+ else
+ sum += check(map, seq);
+ map[i] = '?';
+ i++;
+ }
+ return sum;
+}
+
+int main() {
+ string line;
+ long result = 0;
+ int lines = 0;
+ while (getline(cin, line)) {
+ string map = split(line, " ")[0];
+ vector<string> seqstr = split(split(line, " ")[1], ",");
+ vector<int> seq{};
+ for (auto& e : seqstr)
+ seq.push_back(atoi(e.c_str()));
+
+ unsigned count = 0;
+ for (auto e : seq)
+ count += e;
+ for (auto c : map)
+ count -= c == '#';
+
+ auto v = recurse(map, seq, count, 1, 0);
+ print(line);
+ print(v);
+ result += v;
+ print(result);
+ print("");
+ lines += 1;
+ }
+ print(result);
+ print(lines);
+ return 0;
+}
diff --git a/12/submit.sh b/12/submit.sh
new file mode 100755
index 0000000..116caff
--- /dev/null
+++ b/12/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/12/test.sh b/12/test.sh
new file mode 100755
index 0000000..2fdcb42
--- /dev/null
+++ b/12/test.sh
@@ -0,0 +1,2 @@
+#!/bin/sh
+./build.sh && ./a.out <input