From ae1e96f10b399266825e275ca4a8100ceede9cad Mon Sep 17 00:00:00 2001 From: Thomas Schmucker Date: Thu, 23 Oct 2025 19:28:20 +0200 Subject: days 19-25, aoc 2016 --- 2016/src/day19.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 2016/src/day19.cpp (limited to '2016/src/day19.cpp') diff --git a/2016/src/day19.cpp b/2016/src/day19.cpp new file mode 100644 index 0000000..2d7282f --- /dev/null +++ b/2016/src/day19.cpp @@ -0,0 +1,45 @@ +#include +#include + +using namespace std; + +namespace { + +template +T +fn(T N) + requires std::is_integral_v +{ + return T(1) << static_cast(floor(log2(N))); +} + +void +part1(unsigned N) +{ + cout << (2 * (N - fn(N))) + 1 << '\n'; +} + +void +part2(unsigned N) +{ + auto log_3 = [](double x) { return log(x) / log(3); }; + + auto threes = pow(3, floor(log_3(N - 1))); + if ( N <= 2 * threes ) { + cout << static_cast(N - threes); + } + else { + cout << static_cast(N - threes + N - (2 * threes)); + } + cout << '\n'; +} + +} // namespace + +int +main() +{ + const unsigned puzzle = 3017957; + part1(puzzle); + part2(puzzle); +} -- cgit v1.3