Solutions for Advent of Code 2018 in C++17.
The solution with the highest number is always a "work in progress".
- g++ (GCC) or clang++ (Clang) with support for C++17.
- sakemake
Enter the desired day and part:
cd d1p1
Then build and run:
sm run
Alternatively, something like this may work:
g++ -std=c++17 -O2 -DDATADIR=\"data/\" -I../include ../common/numbers.cpp ../common/turtle.cpp main.cpp -o d1p1 && ./d1p1
- Create a directory for the challenge in question, for day 4 part 2 create a directory named
d4p2. - Create
main.cppfrom scratch, or copy it from a previous challenge. - If the challenge comes with one or more data files, place them in a directory named
datainside thed4p2directory. - When reading files from within
main.cpprefer to theDATADIRdefine, with a space before the filename string. For example:openFile(DATADIR "input.txt"s);.openFileandinput.txtare made-up names. The string literal"sis optional. - See if any of the functions available in
../commonmay be applicable for solving the current challenge. Browsing the headers in../includemay give a better overview (and have more informative comments). - If needed, add a function to
../includeand../commonby first adding the function signature and/or header-only functions in a header file in../includeand then adding the implementation in a.cppfile with the same first name in../common. Add a test-cpp file in../commonby naming it the first name of the file then_test.cpp, so that the test file forbananas.cppisbananas_test.cpp. Follow the pattern of the other*_test.cppfiles.sm testcan be used for running tests in a directory with_test.cppfiles. - Solve the challenge. Adding common functions and classes, with tests that make sure they work correctly, is helpful.
- The
smcommand can be used for building andsm runcan be used for building and running.sm rebuildrebuilds. There is also support for profiling and debug builds. See the sakemake webpage for more information. - Generating project files for QtCreator with
sm pro, then opening it inqtcreator, can be useful for debugging. sm fmtcan be used for formatting the source code. QtCreator can also be configured to ie. format all C++ code with the clang-format style of WebKit, with 99 character long lines.
- License: MIT