aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2017-12-25 15:34:32 +0100
committerLeah Neukirchen <leah@vuxu.org>2017-12-25 15:34:32 +0100
commit5c505911c9a0da95ae4bca311abc5902fbbcb1f3 (patch)
treedcc207b9cf3065861ecb9eefeef0a0b3cb7e495b
parent8f688120afe73ec3b25d31294b5886f5651bde2e (diff)
downloadadventofcode2017-5c505911c9a0da95ae4bca311abc5902fbbcb1f3.tar.gz
adventofcode2017-5c505911c9a0da95ae4bca311abc5902fbbcb1f3.tar.xz
adventofcode2017-5c505911c9a0da95ae4bca311abc5902fbbcb1f3.zip
day24
-rw-r--r--day2457
-rw-r--r--day24.cc51
-rw-r--r--day24.k7
3 files changed, 115 insertions, 0 deletions
diff --git a/day24 b/day24
new file mode 100644
index 0000000..d990a34
--- /dev/null
+++ b/day24
@@ -0,0 +1,57 @@
+24/14
+30/24
+29/44
+47/37
+6/14
+20/37
+14/45
+5/5
+26/44
+2/31
+19/40
+47/11
+0/45
+36/31
+3/32
+30/35
+32/41
+39/30
+46/50
+33/33
+0/39
+44/30
+49/4
+41/50
+50/36
+5/31
+49/41
+20/24
+38/23
+4/30
+40/44
+44/5
+0/43
+38/20
+20/16
+34/38
+5/37
+40/24
+22/17
+17/3
+9/11
+41/35
+42/7
+22/48
+47/45
+6/28
+23/40
+15/15
+29/12
+45/11
+21/31
+27/8
+18/44
+2/17
+46/17
+29/29
+45/50
diff --git a/day24.cc b/day24.cc
new file mode 100644
index 0000000..64e33b0
--- /dev/null
+++ b/day24.cc
@@ -0,0 +1,51 @@
+#include <algorithm>
+#include <iostream>
+#include <numeric>
+#include <vector>
+#include <deque>
+#include <utility>
+
+using namespace std;
+
+
+int
+main()
+{
+ vector<pair<int,int>> d;
+
+ int a, b;
+ char _;
+ while (cin >> a >> _ >> b)
+ d.emplace_back(a, b);
+
+ deque<pair<int,vector<pair<int,int>>>> q{ {0,{}} };
+
+ int p1 = 0;
+ int p2 = 0, p2l = 0;
+ while (!empty(q)) {
+ auto [s, v] = q.front();
+ q.pop_front();
+
+ int sum = accumulate(begin(v), end(v), 0,
+ [](int i, auto &g) { return i + g.first + g.second; });
+ p1 = max(p1, sum);
+ if (size(v) > p2l) {
+ p2 = 0;
+ p2l = size(v);
+ }
+ if (p2l == size(v))
+ p2 = max(p2, sum);
+
+ for (auto p : d)
+ if (p.first == s || p.second == s) {
+ if (find(begin(v), end(v), p) != end(v))
+ continue;
+
+ vector v2 = v;
+ v2.emplace_back(p);
+ q.emplace_back(p.first == s ? p.second : p.first, v2);
+ }
+ }
+
+ cout << p1 << endl << p2 << endl; // 2006 1994
+}
diff --git a/day24.k b/day24.k
new file mode 100644
index 0000000..0f82299
--- /dev/null
+++ b/day24.k
@@ -0,0 +1,7 @@
+d:.:''"/"\'0:`day24
+
+s:,/(,/{v::x[0];r::x[1];{(x@v=*x;r,,x)}'in[*x;]#d^x[1]}')\,(0;,!0)
+|/{+/,/x[1]}'s
+l: |/#:'s[;1]
+|/{+/,/x[1]}'{l=#x[1]}#s
+\\