From be276216631fae2daeeed1c5559cb8c825ad5fe2 Mon Sep 17 00:00:00 2001 From: Matthew Gretton-Dann Date: Thu, 30 Nov 2023 20:29:35 +0000 Subject: [PATCH] Add includes of cassert --- 2017/puzzle-20-02.cc | 8 ++++++-- 2017/puzzle-25-01.cc | 1 + 2018/puzzle-03-01.cc | 1 + 2018/puzzle-03-02.cc | 1 + 2018/puzzle-04-01.cc | 29 +++++++++++++++-------------- 2018/puzzle-04-02.cc | 31 ++++++++++++++++--------------- 2018/puzzle-12-01.cc | 5 +++-- 2018/puzzle-12-02.cc | 1 + 2018/puzzle-14-01.cc | 1 + 2018/puzzle-14-02.cc | 1 + 2021/puzzle-18-01.cc | 2 ++ 2021/puzzle-18-02.cc | 2 ++ 2021/puzzle-20-01.cc | 4 +++- 2021/puzzle-20-02.cc | 4 +++- 2021/puzzle-21-02.cc | 3 +++ 2021/puzzle-25-01.cc | 1 + 2022/graph-utils.h | 11 ++++++----- 2022/puzzle-02-01.cc | 1 + 2022/puzzle-02-02.cc | 1 + 2022/puzzle-03-01.cc | 3 ++- 2022/puzzle-03-02.cc | 1 + 2022/puzzle-05-01.cc | 1 + 2022/puzzle-05-02.cc | 1 + 2022/puzzle-07-01.cc | 1 + 2022/puzzle-07-02.cc | 1 + 2022/puzzle-08-01.cc | 1 + 2022/puzzle-08-02.cc | 1 + 2022/puzzle-11-01.cc | 4 ++++ 2022/puzzle-14-02.cc | 1 + 2022/puzzle-15-01.cc | 11 ++++++----- 2022/puzzle-15-02.cc | 1 + 2022/puzzle-18-01.cc | 4 +++- 2022/puzzle-18-02.cc | 4 +++- 2022/puzzle-21-01.cc | 8 ++++++-- 2022/puzzle-21-02.cc | 24 ++++++++++++++---------- 2022/puzzle-22-01.cc | 7 ++++--- 2022/puzzle-22-02.cc | 11 ++++++----- 2022/puzzle-23-01.cc | 10 ++++++---- 2022/puzzle-23-02.cc | 12 +++++++----- 2022/puzzle-24-01.cc | 1 + 2022/puzzle-24-02.cc | 1 + 41 files changed, 140 insertions(+), 77 deletions(-) diff --git a/2017/puzzle-20-02.cc b/2017/puzzle-20-02.cc index 0a24fc7..d416928 100644 --- a/2017/puzzle-20-02.cc +++ b/2017/puzzle-20-02.cc @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -7,7 +8,10 @@ using Int = long; struct Vector { - Vector(Int x, Int y, Int z) : x_(x), y_(y), z_(z) {} + Vector(Int x, Int y, Int z) + : x_(x), y_(y), z_(z) + { + } Int x() const noexcept { return x_; } Int y() const noexcept { return y_; } @@ -49,7 +53,7 @@ auto operator==(Vector const& lhs, Vector const& rhs) -> bool struct NodeState { NodeState(Vector const& pos, Vector const& velocity, Vector const& accel) - : pos_(pos), velocity_(velocity), accel_(accel) + : pos_(pos), velocity_(velocity), accel_(accel) { } diff --git a/2017/puzzle-25-01.cc b/2017/puzzle-25-01.cc index da532d2..9125dcb 100644 --- a/2017/puzzle-25-01.cc +++ b/2017/puzzle-25-01.cc @@ -4,6 +4,7 @@ #include #include #include +#include using Int = long; using StateName = char; diff --git a/2018/puzzle-03-01.cc b/2018/puzzle-03-01.cc index 5131af2..552dda5 100644 --- a/2018/puzzle-03-01.cc +++ b/2018/puzzle-03-01.cc @@ -11,6 +11,7 @@ #include #include "position.h" +#include using Int = std::int64_t; diff --git a/2018/puzzle-03-02.cc b/2018/puzzle-03-02.cc index 945f221..bb44e35 100644 --- a/2018/puzzle-03-02.cc +++ b/2018/puzzle-03-02.cc @@ -10,6 +10,7 @@ #include #include #include +#include #include "position.h" diff --git a/2018/puzzle-04-01.cc b/2018/puzzle-04-01.cc index 2668b03..054735e 100644 --- a/2018/puzzle-04-01.cc +++ b/2018/puzzle-04-01.cc @@ -11,6 +11,7 @@ #include #include #include +#include using UInt = std::uint64_t; @@ -23,19 +24,19 @@ struct Event UInt pos{1}; std::size_t l{0}; std::stoull(s.substr(pos)); - timestamp_ = std::stoull(s.substr(pos), &l); // year + timestamp_ = std::stoull(s.substr(pos), &l); // year pos += l + 1; timestamp_ *= 12; - timestamp_ += std::stoull(s.substr(pos), &l) - 1; // month + timestamp_ += std::stoull(s.substr(pos), &l) - 1; // month pos += l + 1; - timestamp_ *= 31; // Just need order not actual values. - timestamp_ += std::stoull(s.substr(pos), &l) - 1; // day + timestamp_ *= 31; // Just need order not actual values. + timestamp_ += std::stoull(s.substr(pos), &l) - 1; // day pos += l + 1; timestamp_ *= 24; - timestamp_ += std::stoull(s.substr(pos), &l); // hour + timestamp_ += std::stoull(s.substr(pos), &l); // hour pos += l + 1; timestamp_ *= 60; - timestamp_ += std::stoull(s.substr(pos), &l); // minute + timestamp_ += std::stoull(s.substr(pos), &l); // minute pos += l + 2; if (s.substr(pos) == "falls asleep"s) { wake_up_ = false; @@ -79,11 +80,11 @@ private: auto print_timestamp(UInt timestamp) { std::cout << "[" << timestamp << ": " << timestamp / static_cast(24 * 60 * 31 * 12) << "-" - << std::setw(2) << std::setfill('0') - << 1 + timestamp / static_cast(24 * 60 * 31) % 12 << "-" << std::setw(2) - << std::setfill('0') << 1 + (timestamp / static_cast(24 * 60)) % 31 << " " - << std::setw(2) << std::setfill('0') << (timestamp / 60) % 24 << ":" << std::setw(2) - << std::setfill('0') << timestamp % 60 << "]"; + << std::setw(2) << std::setfill('0') + << 1 + timestamp / static_cast(24 * 60 * 31) % 12 << "-" << std::setw(2) + << std::setfill('0') << 1 + (timestamp / static_cast(24 * 60)) % 31 << " " + << std::setw(2) << std::setfill('0') << (timestamp / 60) % 24 << ":" << std::setw(2) + << std::setfill('0') << timestamp % 60 << "]"; } auto how_sleepy(std::vector const& guard) -> UInt @@ -120,8 +121,8 @@ auto main() -> int } print_timestamp(e.timestamp()); std::cout << ": Guard " << current_it->first << " wakes up after " - << e.timestamp() - asleep_from << " minutes sleep. Has slept a total of " - << how_sleepy(current_it->second) << " minutes.\n"; + << e.timestamp() - asleep_from << " minutes sleep. Has slept a total of " + << how_sleepy(current_it->second) << " minutes.\n"; asleep_from = 0; } } @@ -142,7 +143,7 @@ auto main() -> int std::max_element(sleepiest_guard->second.begin(), sleepiest_guard->second.end()) - sleepiest_guard->second.begin()}; std::cout << "Busiest guard: " << sleepiest_guard_id << " was asleep most in minute " - << sleepiest_minute << "\n"; + << sleepiest_minute << "\n"; std::cout << "Result: " << sleepiest_guard_id * sleepiest_minute << "\n"; return EXIT_SUCCESS; } diff --git a/2018/puzzle-04-02.cc b/2018/puzzle-04-02.cc index 419e159..41bd3c0 100644 --- a/2018/puzzle-04-02.cc +++ b/2018/puzzle-04-02.cc @@ -2,6 +2,7 @@ // Created by Matthew Gretton-Dann on 01/12/2022. // +#include #include #include #include @@ -23,19 +24,19 @@ struct Event UInt pos{1}; std::size_t l{0}; std::stoull(s.substr(pos)); - timestamp_ = std::stoull(s.substr(pos), &l); // year + timestamp_ = std::stoull(s.substr(pos), &l); // year pos += l + 1; timestamp_ *= 12; - timestamp_ += std::stoull(s.substr(pos), &l) - 1; // month + timestamp_ += std::stoull(s.substr(pos), &l) - 1; // month pos += l + 1; - timestamp_ *= 31; // Just need order not actual values. - timestamp_ += std::stoull(s.substr(pos), &l) - 1; // day + timestamp_ *= 31; // Just need order not actual values. + timestamp_ += std::stoull(s.substr(pos), &l) - 1; // day pos += l + 1; timestamp_ *= 24; - timestamp_ += std::stoull(s.substr(pos), &l); // hour + timestamp_ += std::stoull(s.substr(pos), &l); // hour pos += l + 1; timestamp_ *= 60; - timestamp_ += std::stoull(s.substr(pos), &l); // minute + timestamp_ += std::stoull(s.substr(pos), &l); // minute pos += l + 2; if (s.substr(pos) == "falls asleep"s) { wake_up_ = false; @@ -79,11 +80,11 @@ private: auto print_timestamp(UInt timestamp) { std::cout << "[" << timestamp << ": " << timestamp / static_cast(24 * 60 * 31 * 12) << "-" - << std::setw(2) << std::setfill('0') - << 1 + timestamp / static_cast(24 * 60 * 31) % 12 << "-" << std::setw(2) - << std::setfill('0') << 1 + (timestamp / static_cast(24 * 60)) % 31 << " " - << std::setw(2) << std::setfill('0') << (timestamp / 60) % 24 << ":" << std::setw(2) - << std::setfill('0') << timestamp % 60 << "]"; + << std::setw(2) << std::setfill('0') + << 1 + timestamp / static_cast(24 * 60 * 31) % 12 << "-" << std::setw(2) + << std::setfill('0') << 1 + (timestamp / static_cast(24 * 60)) % 31 << " " + << std::setw(2) << std::setfill('0') << (timestamp / 60) % 24 << ":" << std::setw(2) + << std::setfill('0') << timestamp % 60 << "]"; } auto how_sleepy(std::vector const& guard) -> UInt @@ -120,8 +121,8 @@ auto main() -> int } print_timestamp(e.timestamp()); std::cout << ": Guard " << current_it->first << " wakes up after " - << e.timestamp() - asleep_from << " minutes sleep. Has slept a total of " - << how_sleepy(current_it->second) << " minutes.\n"; + << e.timestamp() - asleep_from << " minutes sleep. Has slept a total of " + << how_sleepy(current_it->second) << " minutes.\n"; asleep_from = 0; } } @@ -144,8 +145,8 @@ auto main() -> int } std::cout << "Guard " << guard_sleep.first << " slept most for " << *sleepiest_minute - << " minutes at " << sleepiest_minute - guard_sleep.second.begin() - << " score: " << score << "\n"; + << " minutes at " << sleepiest_minute - guard_sleep.second.begin() + << " score: " << score << "\n"; } std::cout << "Result: " << max_score << "\n"; diff --git a/2018/puzzle-12-01.cc b/2018/puzzle-12-01.cc index bbe64b8..d296e36 100644 --- a/2018/puzzle-12-01.cc +++ b/2018/puzzle-12-01.cc @@ -2,6 +2,7 @@ // Created by Matthew Gretton-Dann on 01/12/2022. // +#include #include #include #include @@ -65,8 +66,8 @@ auto main() -> int for (unsigned i{0}; i < transitions.size(); ++i) { std::cout << ((i & 16) ? plant : soil) << ((i & 8) ? plant : soil) << ((i & 4) ? plant : soil) - << ((i & 2) ? plant : soil) << ((i & 1) ? plant : soil) << " => " << transitions[i] - << "\n"; + << ((i & 2) ? plant : soil) << ((i & 1) ? plant : soil) << " => " << transitions[i] + << "\n"; } constexpr UInt num_runs{20}; for (UInt i{0}; i < num_runs; ++i) { diff --git a/2018/puzzle-12-02.cc b/2018/puzzle-12-02.cc index 82780c3..806b40c 100644 --- a/2018/puzzle-12-02.cc +++ b/2018/puzzle-12-02.cc @@ -2,6 +2,7 @@ // Created by Matthew Gretton-Dann on 01/12/2022. // +#include #include #include #include diff --git a/2018/puzzle-14-01.cc b/2018/puzzle-14-01.cc index 6655d59..f695540 100644 --- a/2018/puzzle-14-01.cc +++ b/2018/puzzle-14-01.cc @@ -2,6 +2,7 @@ // Created by Matthew Gretton-Dann on 01/12/2022. // +#include #include #include #include diff --git a/2018/puzzle-14-02.cc b/2018/puzzle-14-02.cc index 14053ee..7d4907a 100644 --- a/2018/puzzle-14-02.cc +++ b/2018/puzzle-14-02.cc @@ -8,6 +8,7 @@ #include #include #include +#include using Int = std::int64_t; using UInt = std::uint64_t; diff --git a/2021/puzzle-18-01.cc b/2021/puzzle-18-01.cc index 1601de4..2ffdb12 100644 --- a/2021/puzzle-18-01.cc +++ b/2021/puzzle-18-01.cc @@ -1,6 +1,7 @@ #include #include #include +#include using UInt = unsigned long; @@ -9,6 +10,7 @@ struct Item UInt value_; unsigned depth_; }; + using Items = std::vector; auto print1(Items::const_iterator begin, Items::const_iterator end, unsigned current_depth) diff --git a/2021/puzzle-18-02.cc b/2021/puzzle-18-02.cc index 2ab0c9d..17e5d86 100644 --- a/2021/puzzle-18-02.cc +++ b/2021/puzzle-18-02.cc @@ -1,6 +1,7 @@ #include #include #include +#include using UInt = unsigned long; @@ -9,6 +10,7 @@ struct Item UInt value_; unsigned depth_; }; + using Items = std::vector; auto print1(Items::const_iterator begin, Items::const_iterator end, unsigned current_depth) diff --git a/2021/puzzle-20-01.cc b/2021/puzzle-20-01.cc index 7bdcfdf..91defe2 100644 --- a/2021/puzzle-20-01.cc +++ b/2021/puzzle-20-01.cc @@ -1,10 +1,12 @@ +#include #include #include #include struct State { - explicit State(std::string const& rules) : rules_(rules) + explicit State(std::string const& rules) + : rules_(rules) { assert(rules.size() == 512); assert(rules[0] == '.' || rules[511] == '.'); diff --git a/2021/puzzle-20-02.cc b/2021/puzzle-20-02.cc index fe3456b..ae692bc 100644 --- a/2021/puzzle-20-02.cc +++ b/2021/puzzle-20-02.cc @@ -1,10 +1,12 @@ +#include #include #include #include struct State { - explicit State(std::string const& rules) : rules_(rules) + explicit State(std::string const& rules) + : rules_(rules) { assert(rules.size() == 512); assert(rules[0] == '.' || rules[511] == '.'); diff --git a/2021/puzzle-21-02.cc b/2021/puzzle-21-02.cc index f1825c1..303539c 100644 --- a/2021/puzzle-21-02.cc +++ b/2021/puzzle-21-02.cc @@ -1,3 +1,4 @@ +#include #include #include #include @@ -124,6 +125,7 @@ struct State get(new_scorex, scorey, new_posx, posy) += states; } } + void move_player2(unsigned scorex, unsigned scorey, unsigned posx, unsigned posy, unsigned amount, UInt states) { @@ -148,6 +150,7 @@ private: return data_[scorey * target_score * loop_size * loop_size + scorex * loop_size * loop_size + (posy - 1) * loop_size + (posx - 1)]; } + auto get(unsigned scorex, unsigned scorey, unsigned posx, unsigned posy) noexcept -> UInt& { return data_[scorey * target_score * loop_size * loop_size + scorex * loop_size * loop_size + diff --git a/2021/puzzle-25-01.cc b/2021/puzzle-25-01.cc index 94c6f0d..e7cc0c2 100644 --- a/2021/puzzle-25-01.cc +++ b/2021/puzzle-25-01.cc @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/2022/graph-utils.h b/2022/graph-utils.h index d209624..0e7e6e8 100644 --- a/2022/graph-utils.h +++ b/2022/graph-utils.h @@ -6,6 +6,7 @@ #define ADVENT_OF_CODE_GRAPH_UTILS_H #include +#include #include #include #include @@ -133,14 +134,14 @@ auto dijkstra(Node const& initial, Cost initial_cost, TransitionManager transiti current_cost = cost_it->first; assert(iter < nodes.size()); assert(std::accumulate(costs.begin(), costs.end(), std::size_t{0}, [](auto a, auto c) { - return a + c.second.size(); - }) == nodes.size() - iter); + return a + c.second.size(); + }) == nodes.size() - iter); for (auto& nodep : cost_it->second) { if (iter++ % 100'000 == 0) { std::cout << "Iteration: " << iter << " cost " << current_cost - << " total number of nodes: " << nodes.size() - << ", number of costs left to visit: " << costs.size() - << ", number of nodes left: " << (nodes.size() - iter) << '\n'; + << " total number of nodes: " << nodes.size() + << ", number of costs left to visit: " << costs.size() + << ", number of nodes left: " << (nodes.size() - iter) << '\n'; } if (transition_manager.is_finished(*nodep)) { auto result{std::make_pair(*nodep, current_cost)}; diff --git a/2022/puzzle-02-01.cc b/2022/puzzle-02-01.cc index 46b9ce8..2124268 100644 --- a/2022/puzzle-02-01.cc +++ b/2022/puzzle-02-01.cc @@ -6,6 +6,7 @@ #include #include #include +#include using Int = std::int64_t; diff --git a/2022/puzzle-02-02.cc b/2022/puzzle-02-02.cc index 05578d6..7fe8ca2 100644 --- a/2022/puzzle-02-02.cc +++ b/2022/puzzle-02-02.cc @@ -2,6 +2,7 @@ // Created by Matthew Gretton-Dann on 02/12/2022. // +#include #include #include #include diff --git a/2022/puzzle-03-01.cc b/2022/puzzle-03-01.cc index 66b1f45..eb36c45 100644 --- a/2022/puzzle-03-01.cc +++ b/2022/puzzle-03-01.cc @@ -2,6 +2,7 @@ // Created by Matthew Gretton-Dann on 02/12/2022. // +#include #include #include #include @@ -20,7 +21,7 @@ auto main() -> int auto left{line.substr(0, line.size() / 2)}; auto right{line.substr(line.size() / 2)}; std::sort(left.begin(), left.end()); - std::sort(right.begin(), right.end()); + std::sort(right.begin(), right.end()); std::string result; std::set_intersection(left.begin(), left.end(), right.begin(), right.end(), std::back_inserter(result)); diff --git a/2022/puzzle-03-02.cc b/2022/puzzle-03-02.cc index 5bf702b..e91a63b 100644 --- a/2022/puzzle-03-02.cc +++ b/2022/puzzle-03-02.cc @@ -2,6 +2,7 @@ // Created by Matthew Gretton-Dann on 02/12/2022. // +#include #include #include #include diff --git a/2022/puzzle-05-01.cc b/2022/puzzle-05-01.cc index b20c1ce..e0bc948 100644 --- a/2022/puzzle-05-01.cc +++ b/2022/puzzle-05-01.cc @@ -6,6 +6,7 @@ #include #include #include +#include using UInt = std::uint64_t; diff --git a/2022/puzzle-05-02.cc b/2022/puzzle-05-02.cc index abd98a4..d97064b 100644 --- a/2022/puzzle-05-02.cc +++ b/2022/puzzle-05-02.cc @@ -2,6 +2,7 @@ // Created by Matthew Gretton-Dann on 05/12/2021. // +#include #include #include #include diff --git a/2022/puzzle-07-01.cc b/2022/puzzle-07-01.cc index 518690f..13bc54f 100644 --- a/2022/puzzle-07-01.cc +++ b/2022/puzzle-07-01.cc @@ -2,6 +2,7 @@ // Created by Matthew Gretton-Dann on 07/12/2022. // +#include #include #include #include diff --git a/2022/puzzle-07-02.cc b/2022/puzzle-07-02.cc index 32610f9..82ed766 100644 --- a/2022/puzzle-07-02.cc +++ b/2022/puzzle-07-02.cc @@ -2,6 +2,7 @@ // Created by Matthew Gretton-Dann on 07/12/2022. // +#include #include #include #include diff --git a/2022/puzzle-08-01.cc b/2022/puzzle-08-01.cc index f1761b6..fdfc220 100644 --- a/2022/puzzle-08-01.cc +++ b/2022/puzzle-08-01.cc @@ -2,6 +2,7 @@ // Created by Matthew Gretton-Dann on 08/12/2022. // +#include #include #include #include diff --git a/2022/puzzle-08-02.cc b/2022/puzzle-08-02.cc index c848412..2daacf6 100644 --- a/2022/puzzle-08-02.cc +++ b/2022/puzzle-08-02.cc @@ -2,6 +2,7 @@ // Created by Matthew Gretton-Dann on 08/12/2022. // +#include #include #include #include diff --git a/2022/puzzle-11-01.cc b/2022/puzzle-11-01.cc index 77d804f..48403be 100644 --- a/2022/puzzle-11-01.cc +++ b/2022/puzzle-11-01.cc @@ -2,6 +2,7 @@ // Created by Matthew Gretton-Dann on 09/12/2022. // +#include #include #include #include @@ -18,17 +19,20 @@ enum class Op { undef, add, mult, dbl, square }; struct Monkey { auto add_item(UInt score) { items_.push_back(score); } + auto op(Op op) { assert(op == Op::dbl || op == Op::square); op_ = op; } + auto op(Op op, UInt amt) { assert(op == Op::add || op == Op::mult); op_ = op; amt_ = amt; } + auto test(UInt test) { test_ = test; } auto true_monkey(UInt monkey) { true_monkey_ = monkey; } auto false_monkey(UInt monkey) { false_monkey_ = monkey; } diff --git a/2022/puzzle-14-02.cc b/2022/puzzle-14-02.cc index cdbc90e..1f4d564 100644 --- a/2022/puzzle-14-02.cc +++ b/2022/puzzle-14-02.cc @@ -7,6 +7,7 @@ #include #include #include +#include #include "position.h" diff --git a/2022/puzzle-15-01.cc b/2022/puzzle-15-01.cc index 64248eb..eb8bbdc 100644 --- a/2022/puzzle-15-01.cc +++ b/2022/puzzle-15-01.cc @@ -2,6 +2,7 @@ // Created by Matthew Gretton-Dann on 09/12/2022. // +#include #include #include #include @@ -54,14 +55,14 @@ auto main() -> int // Distance(ish) to row we're interested in: Int const row_dist{std::abs(sy - row)}; std::cout << "Sensor (" << sx << ", " << sy << "):\n" - << " Nearest beacon is: " << bx << ", " << by << "\n" - << " Distance: " << dist << "\n" - << " y-Distance to row " << row << ": " << row_dist << "\n"; + << " Nearest beacon is: " << bx << ", " << by << "\n" + << " Distance: " << dist << "\n" + << " y-Distance to row " << row << ": " << row_dist << "\n"; // If that distance is non-negative then we have places the beacon can't be if (row_dist <= dist) { Int const x_dist{dist - row_dist}; std::cout << " x distance left: " << x_dist << "\n" - << " Range: " << sx - x_dist << " - " << sx + x_dist + 1 << "\n"; + << " Range: " << sx - x_dist << " - " << sx + x_dist + 1 << "\n"; Range const missing{sx - x_dist, sx + x_dist + 1}; ranges.insert(missing); } @@ -83,7 +84,7 @@ auto main() -> int } auto b{std::max(r.first, last_pos)}; std::cout << " Taking range start as: " << b << '\n' - << " Adding to count: " << r.second - b << "\n"; + << " Adding to count: " << r.second - b << "\n"; count += (r.second - b); last_pos = r.second; } diff --git a/2022/puzzle-15-02.cc b/2022/puzzle-15-02.cc index d2758a4..dbe33da 100644 --- a/2022/puzzle-15-02.cc +++ b/2022/puzzle-15-02.cc @@ -2,6 +2,7 @@ // Created by Matthew Gretton-Dann on 09/12/2022. // +#include #include #include #include diff --git a/2022/puzzle-18-01.cc b/2022/puzzle-18-01.cc index 91db4db..6b75999 100644 --- a/2022/puzzle-18-01.cc +++ b/2022/puzzle-18-01.cc @@ -2,6 +2,7 @@ // Created by Matthew Gretton-Dann on 16/12/2022. // +#include #include #include #include @@ -21,7 +22,8 @@ using namespace std::string_literals; struct Grid3 { - explicit Grid3(std::size_t size) : size_(size) { map_.resize(size * size * size, false); } + explicit Grid3(std::size_t size) + : size_(size) { map_.resize(size * size * size, false); } auto point(Point3 const& p) const noexcept -> bool { diff --git a/2022/puzzle-18-02.cc b/2022/puzzle-18-02.cc index c3a8e5b..62d73af 100644 --- a/2022/puzzle-18-02.cc +++ b/2022/puzzle-18-02.cc @@ -2,6 +2,7 @@ // Created by Matthew Gretton-Dann on 16/12/2022. // +#include #include #include #include @@ -21,7 +22,8 @@ using namespace std::string_literals; struct Grid3 { - explicit Grid3(std::size_t size) : size_(size) { map_.resize(size * size * size, ' '); } + explicit Grid3(std::size_t size) + : size_(size) { map_.resize(size * size * size, ' '); } auto point(Point3 const& p) const noexcept -> char { diff --git a/2022/puzzle-21-01.cc b/2022/puzzle-21-01.cc index 256eb37..eb3b6af 100644 --- a/2022/puzzle-21-01.cc +++ b/2022/puzzle-21-01.cc @@ -8,6 +8,7 @@ #include #include #include +#include using Int = std::int64_t; using UInt = std::uint64_t; @@ -19,10 +20,13 @@ struct Monkey { Monkey() = default; - explicit Monkey(Int value) : value_(value), value_known_(true) {} + explicit Monkey(Int value) + : value_(value), value_known_(true) + { + } Monkey(std::string lhs, char op, std::string rhs) - : lhs_(std::move(lhs)), rhs_(std::move(rhs)), op_(op) + : lhs_(std::move(lhs)), rhs_(std::move(rhs)), op_(op) { } diff --git a/2022/puzzle-21-02.cc b/2022/puzzle-21-02.cc index 38533ff..c100771 100644 --- a/2022/puzzle-21-02.cc +++ b/2022/puzzle-21-02.cc @@ -8,6 +8,7 @@ #include #include #include +#include using Int = std::int64_t; using UInt = std::uint64_t; @@ -19,10 +20,13 @@ struct Monkey { Monkey() = default; - explicit Monkey(Int value) : value_(value), value_known_(true) {} + explicit Monkey(Int value) + : value_(value), value_known_(true) + { + } Monkey(std::string lhs, char op, std::string rhs) - : lhs_(std::move(lhs)), rhs_(std::move(rhs)), op_(op) + : lhs_(std::move(lhs)), rhs_(std::move(rhs)), op_(op) { } @@ -68,13 +72,13 @@ auto calculate(Int lhs, char op, Int rhs) auto find_lhs(Int result, char op, Int rhs) { switch (op) { - case '+': // result = lhs + rhs -> lhs = result - rhs; + case '+': // result = lhs + rhs -> lhs = result - rhs; return result - rhs; - case '-': // result = lhs - rhs -> lhs = result + rhs; + case '-': // result = lhs - rhs -> lhs = result + rhs; return result + rhs; - case '*': // result = lhs * rhs -> lhs = result / rhs + case '*': // result = lhs * rhs -> lhs = result / rhs return result / rhs; - case '/': // result = lhs / rhs -> lhs = result * rhs; + case '/': // result = lhs / rhs -> lhs = result * rhs; return result * rhs; case '=': return rhs; @@ -86,13 +90,13 @@ auto find_lhs(Int result, char op, Int rhs) auto find_rhs(Int result, Int lhs, char op) { switch (op) { - case '+': // result = lhs + rhs -> rhs = result - lhs; + case '+': // result = lhs + rhs -> rhs = result - lhs; return result - lhs; - case '-': // result = lhs - rhs -> rhs = lhs - result; + case '-': // result = lhs - rhs -> rhs = lhs - result; return lhs - result; - case '*': // result = lhs * rhs -> rhs = result / lhs + case '*': // result = lhs * rhs -> rhs = result / lhs return result / lhs; - case '/': // result = lhs / rhs -> rhs = lhs / result; + case '/': // result = lhs / rhs -> rhs = lhs / result; return lhs / result; case '=': return lhs; diff --git a/2022/puzzle-22-01.cc b/2022/puzzle-22-01.cc index 703c7b2..418da7d 100644 --- a/2022/puzzle-22-01.cc +++ b/2022/puzzle-22-01.cc @@ -2,6 +2,7 @@ // Created by Matthew Gretton-Dann on 16/12/2022. // +#include #include #include #include @@ -150,7 +151,7 @@ auto main() -> int grid.push_back(line); max_row_length = std::max(max_row_length, line.size()); } - for (auto& row : grid) { row.resize(max_row_length, ' ');}; + for (auto& row : grid) { row.resize(max_row_length, ' '); }; std::string instructions; if (!std::getline(std::cin, instructions)) { @@ -183,7 +184,7 @@ auto main() -> int Int const facing{encode_direction(direction)}; std::cout << " Position: " << pos.first << ", " << pos.second << " Facing: " << direction.first - << ", " << direction.second << " = " << facing << "\n"; + << ", " << direction.second << " = " << facing << "\n"; } Int const facing{encode_direction(direction)}; @@ -193,7 +194,7 @@ auto main() -> int std::cout << row << "\n"; } std::cout << "Position: " << pos.first << ", " << pos.second << " Facing: " << direction.first - << ", " << direction.second << " = " << facing << "\n"; + << ", " << direction.second << " = " << facing << "\n"; std::cout << "Encoding: " << pos.second * 1000 + pos.first * 4 + facing; return EXIT_SUCCESS; diff --git a/2022/puzzle-22-02.cc b/2022/puzzle-22-02.cc index d2c798f..521d4c9 100644 --- a/2022/puzzle-22-02.cc +++ b/2022/puzzle-22-02.cc @@ -2,6 +2,7 @@ // Created by Matthew Gretton-Dann on 16/12/2022. // +#include #include #include #include @@ -127,7 +128,7 @@ auto wrap_round(Point const& pos, Point const& direction) -> std::pair std::pair " - << next_pos.first << ", " << next_pos.second << ". Direction " - << direction_char(direction) << " -> " << direction_char(next_direction) << "\n"; + << next_pos.first << ", " << next_pos.second << ". Direction " + << direction_char(direction) << " -> " << direction_char(next_direction) << "\n"; } pos = next_pos; direction = next_direction; @@ -259,7 +260,7 @@ auto main() -> int Int const facing{encode_direction(direction)}; std::cout << " Position: " << pos.first << ", " << pos.second << " Facing: " << direction.first - << ", " << direction.second << " = " << facing << "\n"; + << ", " << direction.second << " = " << facing << "\n"; } Int const facing{encode_direction(direction)}; @@ -269,7 +270,7 @@ auto main() -> int std::cout << row << "\n"; } std::cout << "Position: " << pos.first << ", " << pos.second << " Facing: " << direction.first - << ", " << direction.second << " = " << facing << "\n"; + << ", " << direction.second << " = " << facing << "\n"; std::cout << "Encoding: " << pos.second * 1000 + pos.first * 4 + facing; return EXIT_SUCCESS; diff --git a/2022/puzzle-23-01.cc b/2022/puzzle-23-01.cc index c318462..bc07612 100644 --- a/2022/puzzle-23-01.cc +++ b/2022/puzzle-23-01.cc @@ -2,6 +2,7 @@ // Created by Matthew Gretton-Dann on 16/12/2022. // +#include #include #include #include @@ -45,8 +46,8 @@ auto next_state(Grid const& grid, Dirs const& dirs) -> Grid ++num_pts; if (std::all_of(all_dirs.begin(), all_dirs.end(), [&x, &y, &grid](auto const& dir) { - return grid.at(dir.second + y).at(dir.first + x) == '.'; - })) { + return grid.at(dir.second + y).at(dir.first + x) == '.'; + })) { result.at(y).at(x) = '#'; continue; } @@ -55,8 +56,8 @@ auto next_state(Grid const& grid, Dirs const& dirs) -> Grid Point direction{0, 0}; for (auto const& ds : dirs) { if (std::all_of(ds.begin(), ds.end(), [&x, &y, &grid](auto const& d) { - return grid.at(y + d.second).at(x + d.first) == '.'; - })) { + return grid.at(y + d.second).at(x + d.first) == '.'; + })) { moved = true; direction = ds[1]; } @@ -160,6 +161,7 @@ auto calc_score(Grid const& grid) -> UInt } using namespace std::string_literals; + auto main() -> int { std::string line; diff --git a/2022/puzzle-23-02.cc b/2022/puzzle-23-02.cc index 27216a2..fadb40b 100644 --- a/2022/puzzle-23-02.cc +++ b/2022/puzzle-23-02.cc @@ -2,6 +2,7 @@ // Created by Matthew Gretton-Dann on 16/12/2022. // +#include #include #include #include @@ -45,8 +46,8 @@ auto next_state(Grid const& grid, Dirs const& dirs) -> Grid ++num_pts; if (std::all_of(all_dirs.begin(), all_dirs.end(), [&x, &y, &grid](auto const& dir) { - return grid.at(dir.second + y).at(dir.first + x) == '.'; - })) { + return grid.at(dir.second + y).at(dir.first + x) == '.'; + })) { result.at(y).at(x) = '#'; continue; } @@ -55,8 +56,8 @@ auto next_state(Grid const& grid, Dirs const& dirs) -> Grid Point direction{0, 0}; for (auto const& ds : dirs) { if (std::all_of(ds.begin(), ds.end(), [&x, &y, &grid](auto const& d) { - return grid.at(y + d.second).at(x + d.first) == '.'; - })) { + return grid.at(y + d.second).at(x + d.first) == '.'; + })) { moved = true; direction = ds[1]; } @@ -160,6 +161,7 @@ auto calc_score(Grid const& grid) -> UInt } using namespace std::string_literals; + auto main() -> int { std::string line; @@ -206,6 +208,6 @@ auto main() -> int UInt const score{calc_score(grid)}; std::cout << "Score: " << score << "\n"; - std::cout << "Number of turns: " << num_rounds<< "\n"; + std::cout << "Number of turns: " << num_rounds << "\n"; return EXIT_SUCCESS; } diff --git a/2022/puzzle-24-01.cc b/2022/puzzle-24-01.cc index 7ddcd4b..1b4b749 100644 --- a/2022/puzzle-24-01.cc +++ b/2022/puzzle-24-01.cc @@ -2,6 +2,7 @@ // Created by Matthew Gretton-Dann on 16/12/2022. // +#include #include #include #include diff --git a/2022/puzzle-24-02.cc b/2022/puzzle-24-02.cc index 85c20fa..cb19aef 100644 --- a/2022/puzzle-24-02.cc +++ b/2022/puzzle-24-02.cc @@ -2,6 +2,7 @@ // Created by Matthew Gretton-Dann on 16/12/2022. // +#include #include #include #include