25
This commit is contained in:
parent
40c6998e05
commit
3337b9f536
80
2019/25.cpp
Normal file
80
2019/25.cpp
Normal file
|
@ -0,0 +1,80 @@
|
|||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <string_view>
|
||||
|
||||
#include <aocpp/Startup.hpp>
|
||||
#include <intcode/intcode.hpp>
|
||||
|
||||
using namespace aocpp;
|
||||
using namespace intcode;
|
||||
|
||||
namespace {
|
||||
|
||||
auto RunWithIO(
|
||||
Machine m,
|
||||
std::string const& input
|
||||
) -> void
|
||||
{
|
||||
auto it = input.begin();
|
||||
Run(m,
|
||||
[&]() -> ValueType {
|
||||
if (it < input.end()) { return *it++; }
|
||||
throw std::runtime_error{"insufficient input"};
|
||||
},
|
||||
[&](ValueType o) { std::cout << char(o); });
|
||||
}
|
||||
|
||||
auto Search(std::string & script)
|
||||
{
|
||||
unsigned prev = 0;
|
||||
script += "west\n";
|
||||
for (unsigned i = 1; i < 256; i++) {
|
||||
unsigned curr = i ^ (i >> 1);
|
||||
|
||||
if (curr < prev) {
|
||||
script += "take ";
|
||||
} else {
|
||||
script += "drop ";
|
||||
}
|
||||
|
||||
switch (curr ^ prev) {
|
||||
case (1<<0): script += "cake\n"; break;
|
||||
case (1<<1): script += "sand\n"; break;
|
||||
case (1<<2): script += "asterisk\n"; break;
|
||||
case (1<<3): script += "ornament\n"; break;
|
||||
case (1<<4): script += "festive hat\n"; break;
|
||||
case (1<<5): script += "food ration\n"; break;
|
||||
case (1<<6): script += "space heater\n"; break;
|
||||
case (1<<7): script += "semiconductor\n"; break;
|
||||
}
|
||||
script += "west\n";
|
||||
prev = curr;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
auto main(int argc, char** argv) -> int {
|
||||
std::string script =
|
||||
"north\n" "take sand\n"
|
||||
"north\n" "take space heater\n"
|
||||
"east\n" "take semiconductor\n"
|
||||
"west\n" "south\n" "south\n" "east\n" "take ornament\n"
|
||||
"east\n" "east\n" "west\n" "west\n" "south\n" "take festive hat\n"
|
||||
"east\n" "take asterisk\n"
|
||||
"south\n" "east\n" "take cake\n"
|
||||
"east\n" /* electromagnet */ "south\n" "north\n" "west\n"
|
||||
"west\n" "west\n" "take food ration\n"
|
||||
"east\n" "north\n" "west\n"
|
||||
"west\n" /* photons */
|
||||
"east\n" "north\n" "west\n"
|
||||
"west\n" /* molten lava */ "west\n" "east\n" "north\n" /* infinite loop */ "north\n";
|
||||
|
||||
Search(script);
|
||||
|
||||
RunWithIO(Machine{ParseStream(aocpp::Startup(argc, argv))}, script);
|
||||
}
|
|
@ -60,3 +60,6 @@ target_link_libraries(23 aocpp intcode)
|
|||
|
||||
add_executable(24 24.cpp)
|
||||
target_link_libraries(24 aocpp)
|
||||
|
||||
add_executable(25 25.cpp)
|
||||
target_link_libraries(25 aocpp intcode)
|
||||
|
|
17
CMakePresets.json
Normal file
17
CMakePresets.json
Normal file
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"version": 2,
|
||||
"configurePresets": [
|
||||
{
|
||||
"name": "preset",
|
||||
"displayName": "Configure preset using toolchain file",
|
||||
"description": "Sets Ninja generator, build and install directory",
|
||||
"generator": "Ninja",
|
||||
"binaryDir": "${sourceDir}/out/build/${presetName}",
|
||||
"cacheVariables": {
|
||||
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
|
||||
"CMAKE_TOOLCHAIN_FILE": "",
|
||||
"CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue
Block a user