Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Day 24 #99

Merged
merged 3 commits into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions 2023/data/24/example.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
19, 13, 30 @ -2, 1, -2
18, 19, 22 @ -1, -1, -2
20, 25, 34 @ -2, -2, -4
12, 31, 28 @ -1, -2, -1
20, 19, 15 @ 1, -5, -3
300 changes: 300 additions & 0 deletions 2023/data/24/input.txt

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions 2023/solvelib/08/day08.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ auto finishing_nodes(std::map<std::string, node> const& network) {
auto timings_matrix(std::string_view instr, std::map<std::string, node> const& network,
std::span<std::string> sources, std::span<std::string> destinations) {

xmas::basic_matrix<std::uint64_t> timing_matrix(sources.size(), destinations.size(), 0);
xmas::dense_matrix<std::uint64_t> timing_matrix(sources.size(), destinations.size(), 0);

xmas::views::iota<std::size_t> rows(0, timing_matrix.nrows());
xmas::views::iota<std::size_t> cols(0, timing_matrix.ncols());
Expand All @@ -156,7 +156,7 @@ auto timings_matrix(std::string_view instr, std::map<std::string, node> const& n
}

std::uint64_t compute_permutation(
xmas::basic_matrix<std::uint64_t> timings, std::vector<std::uint64_t> selected) {
xmas::dense_matrix<std::uint64_t> timings, std::vector<std::uint64_t> selected) {
assert(selected.size() == timings.nrows());

std::vector<std::uint64_t> t(selected.size());
Expand All @@ -169,7 +169,7 @@ std::uint64_t compute_permutation(
}

std::uint64_t find_best_permutation(
xmas::basic_matrix<std::uint64_t> timings, std::vector<std::uint64_t>& selected_finishers) {
xmas::dense_matrix<std::uint64_t> timings, std::vector<std::uint64_t>& selected_finishers) {
std::size_t row = selected_finishers.size();
if (row == timings.nrows()) {
return compute_permutation(timings, selected_finishers);
Expand Down
12 changes: 6 additions & 6 deletions 2023/solvelib/17/day17.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void possible_moves(xmas::views::text_matrix map, state s, std::size_t min_steps

using queue = std::priority_queue<state, std::vector<state>, bool (*)(state const&, state const&)>;

[[maybe_unused]] auto fmt_curr_state(std::array<xmas::basic_matrix<heat_t>, 4> const& visited,
[[maybe_unused]] auto fmt_curr_state(std::array<xmas::dense_matrix<heat_t>, 4> const& visited,
state s) {
return xmas::lazy_string([&visited, s] {
std::stringstream ss;
Expand Down Expand Up @@ -254,11 +254,11 @@ std::uint64_t solve(std::string& input, std::size_t min_steps, std::size_t max_s
// choice of heuristic such that I can short-circuit once I've found a solution.
auto max_heat = std::numeric_limits<heat_t>::max();

std::array<xmas::basic_matrix<heat_t>, 4> visited{
xmas::basic_matrix<heat_t>(map.nrows(), map.ncols(), max_heat),
xmas::basic_matrix<heat_t>(map.nrows(), map.ncols(), max_heat),
xmas::basic_matrix<heat_t>(map.nrows(), map.ncols(), max_heat),
xmas::basic_matrix<heat_t>(map.nrows(), map.ncols(), max_heat),
std::array<xmas::dense_matrix<heat_t>, 4> visited{
xmas::dense_matrix<heat_t>(map.nrows(), map.ncols(), max_heat),
xmas::dense_matrix<heat_t>(map.nrows(), map.ncols(), max_heat),
xmas::dense_matrix<heat_t>(map.nrows(), map.ncols(), max_heat),
xmas::dense_matrix<heat_t>(map.nrows(), map.ncols(), max_heat),
};

heap queue;
Expand Down
6 changes: 3 additions & 3 deletions 2023/solvelib/21/day21.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ coords find_start(xmas::views::text_matrix map) {

constexpr auto sentinel = std::numeric_limits<std::size_t>::max();

void bfs(xmas::views::text_matrix map, xmas::basic_matrix<std::size_t>& distances, std::size_t d,
void bfs(xmas::views::text_matrix map, xmas::dense_matrix<std::size_t>& distances, std::size_t d,
coords pos, std::back_insert_iterator<std::vector<coords>> enqueuer) {
if (distances[pos.row][pos.col] != sentinel) {
return;
Expand Down Expand Up @@ -80,7 +80,7 @@ void bfs(xmas::views::text_matrix map, xmas::basic_matrix<std::size_t>& distance
}

[[maybe_unused]] auto fmt_map(
xmas::views::text_matrix map, xmas::basic_matrix<std::size_t>& distance) {
xmas::views::text_matrix map, xmas::dense_matrix<std::size_t>& distance) {
return xmas::lazy_string([map, &distance]() -> std::string {
std::stringstream ss;
for (std::size_t i = 0; i < map.nrows(); ++i) {
Expand All @@ -101,7 +101,7 @@ void bfs(xmas::views::text_matrix map, xmas::basic_matrix<std::size_t>& distance

std::pair<std::size_t, std::size_t> count_parities(
xmas::views::text_matrix map, std::size_t nsteps, coords start) {
xmas::basic_matrix<std::size_t> distance(map.nrows(), map.ncols(), sentinel);
xmas::dense_matrix<std::size_t> distance(map.nrows(), map.ncols(), sentinel);

std::vector queue{start};
for (std::size_t s = 0; s <= nsteps; ++s) {
Expand Down
4 changes: 2 additions & 2 deletions 2023/solvelib/22/day22.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ std::vector<block> parse(std::string_view input) {
return blocks;
}

[[maybe_unused]] auto fmt_map(xmas::basic_matrix<std::size_t>& map, std::span<const block>) {
[[maybe_unused]] auto fmt_map(xmas::dense_matrix<std::size_t>& map, std::span<const block>) {
return xmas::lazy_string([&map] {
std::stringstream ss;
for (auto r : map.rows()) {
Expand All @@ -127,7 +127,7 @@ void simulate_drop(std::span<block> blocks) {
auto max_x = rng::max(blocks | v::transform([](block const& b) { return b.upper.x; }));
auto max_y = rng::max(blocks | v::transform([](block const& b) { return b.upper.y; }));

xmas::basic_matrix<std::size_t> map(max_x + 1, max_y + 1, placeholder_id);
xmas::dense_matrix<std::size_t> map(max_x + 1, max_y + 1, placeholder_id);
xlog::debug("Detected {} rows and {} columns", map.nrows(), map.ncols());

for (block& b : blocks) {
Expand Down
4 changes: 2 additions & 2 deletions 2023/solvelib/23/day23.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ enum BOOL : std::uint8_t {
};

std::array<temp_edge, 4>::iterator explore(xmas::views::text_matrix map,
xmas::basic_matrix<BOOL>& visited, std::array<temp_edge, 4>::iterator it, temp_edge tip,
xmas::dense_matrix<BOOL>& visited, std::array<temp_edge, 4>::iterator it, temp_edge tip,
heading towards) {
tip.step(towards);
while (map.at(tip.pos) == char(towards)) {
Expand Down Expand Up @@ -185,7 +185,7 @@ void find_all_nodes(xmas::views::text_matrix map, graph& g) {

graph build_graph(xmas::views::text_matrix map) {
graph g;
xmas::basic_matrix<BOOL> visited(map.nrows(), map.ncols(), FALSE);
xmas::dense_matrix<BOOL> visited(map.nrows(), map.ncols(), FALSE);

// Start point
assert(map.at(0, 1) == '.');
Expand Down
Loading
Loading