diff --git a/adventofcode/2023/day/04/aoc_23_day_4_scratchcards.cpp b/adventofcode/2023/day/04/scratchcards.cpp similarity index 93% rename from adventofcode/2023/day/04/aoc_23_day_4_scratchcards.cpp rename to adventofcode/2023/day/04/scratchcards.cpp index ed8b5bf..95fb2ae 100644 --- a/adventofcode/2023/day/04/aoc_23_day_4_scratchcards.cpp +++ b/adventofcode/2023/day/04/scratchcards.cpp @@ -6,6 +6,8 @@ #include #include +#define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) + int main() { auto ans{std::make_pair(0,0)}; @@ -39,7 +41,9 @@ int main() for(int j{0}; j < matching_numbers_per_card[i]; j++) num_cards[i+1+j] += num_cards[i]; +#if GCC_VERSION > 120000 ans.second = std::ranges::fold_left(num_cards, 0, std::plus()); +#endif std::cout << "Part one: " << ans.first << ".\nPart two: " << ans.second << ".\n"; diff --git a/adventofcode/2023/day/08/aoc_23_day_8_haunted_wasteland.cpp b/adventofcode/2023/day/08/haunted_wasteland.cpp similarity index 86% rename from adventofcode/2023/day/08/aoc_23_day_8_haunted_wasteland.cpp rename to adventofcode/2023/day/08/haunted_wasteland.cpp index 5961062..fc4a250 100644 --- a/adventofcode/2023/day/08/aoc_23_day_8_haunted_wasteland.cpp +++ b/adventofcode/2023/day/08/haunted_wasteland.cpp @@ -1,5 +1,7 @@ #include +#define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) + using std::string; void read_input(); @@ -56,6 +58,7 @@ void read_input() } } +// TODO end-to-end part two (cf. d251eef) template integer solve(bool is_part_two) { integer ans{0}; @@ -71,7 +74,11 @@ template integer solve(bool is_part_two) else if(instructions[i]=='R') s = M.at(s).second; else +#if GCC_VERSION > 120000 throw std::domain_error(std::format("Instruction is neither L nor R: {}.", instructions[i])); +#else + throw std::domain_error("Instruction is neither L nor R: " + std::string(1, instructions[i]) + "."); +#endif i = (i+1)%static_cast((instructions.length())); ans++; diff --git a/adventofcode/2023/day/22/sand_slabs.cpp b/adventofcode/2023/day/22/sand_slabs.cpp index 897d160..ac6a266 100644 --- a/adventofcode/2023/day/22/sand_slabs.cpp +++ b/adventofcode/2023/day/22/sand_slabs.cpp @@ -6,9 +6,6 @@ #include #define FOR(i, a, b) for (decltype(b) i = (a) ; i < (b) ; ++i) -#define REP(i, n) FOR(i, 0, n) -#define RFOR(i, b, a) for (decltype(a) i = (b) ; i > (a) ; --i) -#define RREP(i, n) RFOR(i, n, 0) struct point { int x, y, z; point(int x, int y, int z) : x(x), y(y), z(z) {} }; @@ -20,8 +17,14 @@ bool operator==(point const& p, point const& q) using std::pair; using std::vector; +#define GCC_VERSION (__GNUC__ * 10000 \ + + __GNUC_MINOR__ * 100 \ + + __GNUC_PATCHLEVEL__) + using std::ranges::count_if; +#if GCC_VERSION > 120000 using std::ranges::fold_left; +#endif using std::ranges::sort; using brick = pair; @@ -107,7 +110,7 @@ bool is_supported(brick b, vector const& bricks){ } void gravity(vector& bricks){ - std::ranges::sort(bricks, [](brick const& lhs, brick const& rhs){ return lhs.first.z < rhs.first.z; }); + sort(bricks, [](brick const& lhs, brick const& rhs){ return lhs.first.z < rhs.first.z; }); vector lower_bricks; for(brick& b : bricks){ while(!is_supported(b, lower_bricks)) b.first.z--, b.second.z--; @@ -141,8 +144,12 @@ int chainsize(brick b, vector const& bricks) pair solve(vector& bricks) { gravity(bricks); +#if GCC_VERSION > 120000 return std::make_pair(count_if(bricks, [&bricks](brick b){ return disintegrable(b, bricks);}), fold_left(bricks, 0, [&bricks](int n, brick b){ return n+chainsize(b, bricks);})); +#else + return std::make_pair(0, 0); +#endif }