aoc24: add day10
This commit is contained in:
4
dat/24/ex/10a.txt
Normal file
4
dat/24/ex/10a.txt
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
0123
|
||||||
|
1234
|
||||||
|
8765
|
||||||
|
9876
|
||||||
7
dat/24/ex/10b.txt
Normal file
7
dat/24/ex/10b.txt
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
...0...
|
||||||
|
...1...
|
||||||
|
...2...
|
||||||
|
6543456
|
||||||
|
7.....7
|
||||||
|
8.....8
|
||||||
|
9.....9
|
||||||
7
dat/24/ex/10c.txt
Normal file
7
dat/24/ex/10c.txt
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
..90..9
|
||||||
|
...1.98
|
||||||
|
...2..7
|
||||||
|
6543456
|
||||||
|
765.987
|
||||||
|
876....
|
||||||
|
987....
|
||||||
7
dat/24/ex/10d.txt
Normal file
7
dat/24/ex/10d.txt
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
10..9..
|
||||||
|
2...8..
|
||||||
|
3...7..
|
||||||
|
4567654
|
||||||
|
...8..3
|
||||||
|
...9..2
|
||||||
|
.....01
|
||||||
8
dat/24/ex/10e.txt
Normal file
8
dat/24/ex/10e.txt
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
89010123
|
||||||
|
78121874
|
||||||
|
87430965
|
||||||
|
96549874
|
||||||
|
45678903
|
||||||
|
32019012
|
||||||
|
01329801
|
||||||
|
10456732
|
||||||
40
dat/24/re/10.txt
Normal file
40
dat/24/re/10.txt
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
6541001098012789610347890107654656710323
|
||||||
|
7832102127643898701256521218323465891410
|
||||||
|
8996543034556789650987434309012534892565
|
||||||
|
3887689678965876501874345892105621763676
|
||||||
|
4305678563456903416765676756898760654980
|
||||||
|
5214107852107812321254382347872108901221
|
||||||
|
6543236943056921010341291078963457654338
|
||||||
|
7896545987045430010980012569454968983549
|
||||||
|
3217830656189899121676101430356879892678
|
||||||
|
2106921043210778234585232321267898761432
|
||||||
|
3478854430345665056798743410456901050501
|
||||||
|
4569763521012552143895654501345012347670
|
||||||
|
3654012678903443212104309690432167898981
|
||||||
|
2783656987654874908765218781201254012567
|
||||||
|
1092347897893965889034765670387063013498
|
||||||
|
1001298756102456776121874989496122110901
|
||||||
|
2310891043201307655430923876565434325892
|
||||||
|
3456780103011218967649810189410145456743
|
||||||
|
2561078212320989858236702107320236787654
|
||||||
|
1232569343423874749145893678741199899873
|
||||||
|
0343454358514565632098704569632087684562
|
||||||
|
0456789969609034501347612189323456893001
|
||||||
|
1499876878798123101256543079012548762110
|
||||||
|
2387905462687678871212344568187659450223
|
||||||
|
3456012301056549960305650127691098321054
|
||||||
|
3456732102345832154454781034540107650169
|
||||||
|
2369847898738981023763692321121256743278
|
||||||
|
1078456654567670119832103400012349894361
|
||||||
|
0012387763456543208041076510123412765010
|
||||||
|
7650196892565454589107889623296503854321
|
||||||
|
8943256781074303673236908774387654983432
|
||||||
|
8912965890985210984365219985345015676541
|
||||||
|
7607834187866789875434308776236723498650
|
||||||
|
6506543045679012766923105698109894567743
|
||||||
|
5410432134988703457810014567056210754892
|
||||||
|
0322345028767845893456723459847349889701
|
||||||
|
1201276719454936712679801210738256776545
|
||||||
|
2450989805103221604589752345629145480230
|
||||||
|
2347823456012120113298943238710076591121
|
||||||
|
1056910147893012320107654109656789432012
|
||||||
@@ -4,13 +4,15 @@ set(HEADERS
|
|||||||
set(SOURCES
|
set(SOURCES
|
||||||
"aoc.cpp"
|
"aoc.cpp"
|
||||||
"day01.cpp"
|
"day01.cpp"
|
||||||
"day02.cpp"
|
# "day02.cpp"
|
||||||
"day03.cpp"
|
"day03.cpp"
|
||||||
"day04.cpp"
|
# "day04.cpp"
|
||||||
"day05.cpp"
|
"day05.cpp"
|
||||||
"day06.cpp"
|
"day06.cpp"
|
||||||
"day07.cpp"
|
"day07.cpp"
|
||||||
"day08.cpp"
|
"day08.cpp"
|
||||||
|
"day09.cpp"
|
||||||
|
"day10.cpp"
|
||||||
)
|
)
|
||||||
add_library(aoc24 STATIC ${HEADERS} ${SOURCES})
|
add_library(aoc24 STATIC ${HEADERS} ${SOURCES})
|
||||||
target_include_directories(aoc24
|
target_include_directories(aoc24
|
||||||
|
|||||||
@@ -19,13 +19,15 @@ auto entry([[maybe_unused]]std::span<char const*> const& args) -> std::expected<
|
|||||||
|
|
||||||
switch (day) {
|
switch (day) {
|
||||||
case 1: return day01(args);
|
case 1: return day01(args);
|
||||||
case 2: return day02(args);
|
// case 2: return day02(args);
|
||||||
case 3: return day03(args);
|
case 3: return day03(args);
|
||||||
case 4: return day04(args);
|
// case 4: return day04(args);
|
||||||
case 5: return day05(args);
|
case 5: return day05(args);
|
||||||
case 6: return day06(args);
|
case 6: return day06(args);
|
||||||
case 7: return day07(args);
|
case 7: return day07(args);
|
||||||
case 8: return day08(args);
|
case 8: return day08(args);
|
||||||
|
// case 9: return day09(args);
|
||||||
|
case 10: return day10(args);
|
||||||
default:
|
default:
|
||||||
return aoc::make_error(fmt::format("day {}", day), std::errc::not_supported);
|
return aoc::make_error(fmt::format("day {}", day), std::errc::not_supported);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ namespace rbr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto aoc24::day07([[maybe_unused]]std::span<char const*> const& args) -> std::expected<void, aoc::error> {
|
auto aoc24::day07([[maybe_unused]]std::span<char const*> const& args) -> std::expected<void, aoc::error> {
|
||||||
auto res = aoc::read_text("./dat/24/re/07.txt");
|
auto res = aoc::read_text("./dat/24/ex/07.txt");
|
||||||
if (!res) return std::unexpected(res.error());
|
if (!res) return std::unexpected(res.error());
|
||||||
auto const txt = *res;
|
auto const txt = *res;
|
||||||
|
|
||||||
|
|||||||
@@ -3,5 +3,5 @@
|
|||||||
#include "fmt/format.h"
|
#include "fmt/format.h"
|
||||||
|
|
||||||
auto aoc24::day08([[maybe_unused]]std::span<char const*> const& args) -> std::expected<void, aoc::error> {
|
auto aoc24::day08([[maybe_unused]]std::span<char const*> const& args) -> std::expected<void, aoc::error> {
|
||||||
return aoc::make_error("day 8", std::errc::not_supported);
|
return aoc::make_error("", std::errc::not_supported);
|
||||||
}
|
}
|
||||||
|
|||||||
7
sol/24/day09.cpp
Normal file
7
sol/24/day09.cpp
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#include "aoc.hpp"
|
||||||
|
#include "aoc/utils.hpp"
|
||||||
|
#include "fmt/format.h"
|
||||||
|
|
||||||
|
auto aoc24::day09([[maybe_unused]]std::span<char const*> const& args) -> std::expected<void, aoc::error> {
|
||||||
|
return aoc::make_error("", std::errc::not_supported);
|
||||||
|
}
|
||||||
84
sol/24/day10.cpp
Normal file
84
sol/24/day10.cpp
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
#include <utility>
|
||||||
|
#include <vector>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <numeric>
|
||||||
|
|
||||||
|
#include "aoc.hpp"
|
||||||
|
#include "aoc/utils.hpp"
|
||||||
|
#include "fmt/format.h"
|
||||||
|
|
||||||
|
using namespace aoc::types;
|
||||||
|
using namespace std::string_view_literals;
|
||||||
|
|
||||||
|
namespace lpf {
|
||||||
|
using edge_t = std::pair<class node, class node>;
|
||||||
|
using edges_t = std::vector<edge_t>;
|
||||||
|
|
||||||
|
class node {
|
||||||
|
public:
|
||||||
|
node(i32 id, i32 value, edges_t const& edges)
|
||||||
|
: m_id(id), m_value(value), m_edges(edges) {}
|
||||||
|
|
||||||
|
auto operator==(node const& other) const -> bool {
|
||||||
|
return m_id == other.m_id && m_value == other.m_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto id() const -> i32 { return m_id; }
|
||||||
|
auto value() const -> i32 { return m_value; }
|
||||||
|
auto edges() const -> edges_t const& { return m_edges; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
i32 m_id;
|
||||||
|
i32 m_value;
|
||||||
|
edges_t m_edges;
|
||||||
|
};
|
||||||
|
|
||||||
|
class trail {
|
||||||
|
public:
|
||||||
|
trail(std::string const& str) {
|
||||||
|
auto lines = str | std::views::split("\n"sv)
|
||||||
|
| std::views::transform(
|
||||||
|
[](auto const& c_str) {
|
||||||
|
return std::string_view(
|
||||||
|
std::begin(c_str),
|
||||||
|
std::end(c_str)
|
||||||
|
);
|
||||||
|
})
|
||||||
|
| std::views::filter([](auto const& strv) { return !strv.empty(); })
|
||||||
|
| std::ranges::to<std::vector>();
|
||||||
|
|
||||||
|
m_rows = lines.size();
|
||||||
|
m_cols = std::begin(lines)->size();
|
||||||
|
|
||||||
|
std::ranges::for_each(lines, [&](auto const& str) {
|
||||||
|
std::ranges::for_each(str, [&](auto const& ch) {
|
||||||
|
if (std::isdigit(ch)) m_data.emplace_back(ch - '0');
|
||||||
|
else m_data.emplace_back(0xFF);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
auto at(usize row, usize col) const -> u8 {
|
||||||
|
if (row >= m_rows || col >= m_cols) return 0;
|
||||||
|
return m_data[row * m_cols + col];
|
||||||
|
}
|
||||||
|
auto rows() const -> usize { return m_rows; }
|
||||||
|
auto cols() const -> usize { return m_cols; }
|
||||||
|
auto data() const -> std::vector<u8> const& { return m_data; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
usize m_rows;
|
||||||
|
usize m_cols;
|
||||||
|
std::vector<u8> m_data;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
auto aoc24::day10([[maybe_unused]]std::span<char const*> const& args) -> std::expected<void, aoc::error> {
|
||||||
|
auto res = aoc::read_text("./dat/24/ex/10a.txt");
|
||||||
|
if (!res) return std::unexpected(res.error());
|
||||||
|
auto const txt = *res;
|
||||||
|
|
||||||
|
lpf::trail trail{txt};
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user