aboutsummaryrefslogtreecommitdiff
path: root/src/2018/day4/aoc.cpp
diff options
context:
space:
mode:
authorkaiwu <kaiwu2004@gmail.com>2022-04-08 21:44:23 +0800
committerkaiwu <kaiwu2004@gmail.com>2022-04-08 21:44:23 +0800
commit133b01f692c98d12a82e4b102ea0ae5fc2c558ad (patch)
treefa13e5eeec7dfbb6429278394774d148e889a421 /src/2018/day4/aoc.cpp
parent875915109841d2acb5b30bafcba1d0e342d88cdd (diff)
downloadadvent-of-code-133b01f692c98d12a82e4b102ea0ae5fc2c558ad.tar.gz
advent-of-code-133b01f692c98d12a82e4b102ea0ae5fc2c558ad.zip
offtime
Diffstat (limited to 'src/2018/day4/aoc.cpp')
-rw-r--r--src/2018/day4/aoc.cpp60
1 files changed, 46 insertions, 14 deletions
diff --git a/src/2018/day4/aoc.cpp b/src/2018/day4/aoc.cpp
index 7166609..9b9283d 100644
--- a/src/2018/day4/aoc.cpp
+++ b/src/2018/day4/aoc.cpp
@@ -5,6 +5,40 @@
namespace aoc2018 {
+int mostlikely(guard* g) {
+ // int minute[60] = {0};
+ // for (int i = 0; i < 60; i++) {
+ // int ms = g->offtime[i];
+ // int j = i;
+ // while (ms-- > 0) {
+ // minute[j++] += 1;
+ // }
+ // }
+ // int most{INT32_MIN};
+ // int highest{INT32_MIN};
+ for (int i = 0; i < 60; i++) {
+ // printf("%02d ", minute[i]);
+ printf("%02d ", g->offtime[i]);
+ // if (minute[i] > highest) {
+ // most = i;
+ // highest = minute[i];
+ // }
+ if ((i + 1) % 10 == 0) {
+ printf("\n");
+ }
+ }
+ // printf("%d\n", most);
+ return 0;
+}
+
+int totaloff(guard* g) {
+ int d{0};
+ for (int i = 0; i < 60; i++) {
+ d += g->offtime[i];
+ }
+ return d;
+}
+
int day4(line_view file) {
std::vector<guard> gs;
per_line(file, [&gs](line_view lv) {
@@ -25,10 +59,10 @@ int day4(line_view file) {
}
return false;
});
- // std::for_each(gs.begin(), gs.end(), [](const guard& g) {
- // printf("%02d-%02d %02d:%02d #%d %s\n", g.timestamp.month, g.timestamp.day, g.timestamp.hour, g.timestamp.minute,
- // g.id, g.status == guard::on ? "on" : "off");
- // });
+ std::for_each(gs.begin(), gs.end(), [](const guard& g) {
+ printf("%02d-%02d %02d:%02d #%d %s\n", g.timestamp.month, g.timestamp.day, g.timestamp.hour, g.timestamp.minute,
+ g.id, g.status == guard::on ? "on" : "off");
+ });
std::unordered_map<int, guard*> hs;
guard* p{nullptr};
@@ -62,23 +96,21 @@ int day4(line_view file) {
guard* g = nullptr;
} mostoff;
- auto totaloff = [](guard* g) {
- int d{0};
- for (int i = 0; i < 60; i++) {
- d += g->offtime[i];
- }
- return d;
- };
-
for (auto& kv : hs) {
int off = totaloff(kv.second);
- printf("%d: %d\n", kv.second->id, off);
+ // printf("%d: %d\n", kv.second->id, off);
if (mostoff.g == nullptr || mostoff.off < off) {
mostoff.g = kv.second;
mostoff.off = off;
}
}
- printf("%d: %d\n", mostoff.g->id, mostoff.off);
+
+ int minute = mostlikely(mostoff.g);
+ printf("\n%d: %d at %d\n", mostoff.g->id, mostoff.off, minute);
+
+ for (auto& kv : hs) {
+ delete kv.second;
+ }
return 0;
}