aboutsummaryrefslogtreecommitdiff
path: root/src/2019/day8/aoc.cpp
diff options
context:
space:
mode:
authorkaiwu <kaiwu2004@gmail.com>2022-05-14 11:11:00 +0800
committerkaiwu <kaiwu2004@gmail.com>2022-05-14 11:11:00 +0800
commitcd8458f37abae6b5d1f7f289a22e506da8070357 (patch)
treead77724654c4d4c6e821dd7be9e4dfbc1f736c09 /src/2019/day8/aoc.cpp
parentdfe25822f031cebea626eca29ea304af5598f657 (diff)
downloadadvent-of-code-cd8458f37abae6b5d1f7f289a22e506da8070357.tar.gz
advent-of-code-cd8458f37abae6b5d1f7f289a22e506da8070357.zip
2019 day8 part1
Diffstat (limited to 'src/2019/day8/aoc.cpp')
-rw-r--r--src/2019/day8/aoc.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/2019/day8/aoc.cpp b/src/2019/day8/aoc.cpp
index f0cbc1b..c92a054 100644
--- a/src/2019/day8/aoc.cpp
+++ b/src/2019/day8/aoc.cpp
@@ -1,5 +1,43 @@
#include "aoc.h"
+#include <algorithm>
namespace aoc2019 {
+struct digits {
+ int chars[10] = {0};
+};
+
+static void count_digit(const char* p1, const char* p2, digits* p) {
+ while (p1 < p2) {
+ p->chars[*p1 - '0'] += 1;
+ p1++;
+ }
+}
+
+std::pair<int, int> day8(line_view file) {
+ digits ds[100];
+ int x = 6 * 25;
+ for (int i = 0; i < 100; i++) {
+ const char* p1 = file.line + i * x;
+ const char* p2 = file.line + (i + 1) * x;
+ count_digit(p1, p2, &ds[i]);
+ }
+
+ struct ct {
+ int zeros = 0;
+ int times = 0;
+ } cs[100];
+
+ for (int i = 0; i < 100; i++) {
+ cs[i].zeros = ds[i].chars[0];
+ cs[i].times = ds[i].chars[1] * ds[i].chars[2];
+ // for (int j : {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}) {
+ // printf("%d ", ds[i].chars[j]);
+ // }
+ // printf("\n");
+ }
+
+ std::sort(cs, cs + 100, [](ct c1, ct c2) { return c1.zeros < c2.zeros; });
+ return {cs[0].times, 0};
}
+} // namespace aoc2019