My first Advent of Code with solutions written in C++.
I'm doing this to improve my C++ knowledge. I'll try to code using these rules:
- comment the new things I discover
- use OOP if possible
- find the fastest algorithm
- naming variables self-explanatory
- don't nest my code excessively
The code will be redundant because I will keep all the ways I did it.
I use a script to create a new directory for each day with inside a day00.cc file that already has a template and an input.txt file where to put the input puzzle:
|____day01
| |____day01.cc
| |____input.txt
|____day02
| |____day02.cc
| |____input.txt
|____day03
| |____day03.cc
| |____input.txt
:For use the script digit on terminal ./create_day <day>, before this remember to make script.sh executable with the command: chmod +x create_day.sh.
I use a non-standard library from the GNU Compiler Collection, called <bit/stdc++.h>. It is basically a header file that includes every standard library.
I know that it use a lot in competitive programming and it's useful because it avoids adding new header files every time. Of course outside this range it's not a good practice and increases compile time.
For Mac users compiling with g++ will it use clang, to use GNU you need g++-12, you can create alias ( alias g++ = "g++-12" ) or simply use Code Runner in VSCode and modify settings in setting.json:
"code-runner.executorMap": { "cpp": "cd $dir && g++-12 $fileName && $dir/a.out" }I know some people create a test.txt to test the code before submitting it with the example in the text of the puzzle, thus also knowing the expected result (the first throttle for an incorrect submission is 1 minute, and it gets even longer if you mess up again). I think it's a good idea to be faster and not waste time but I won't 👇
I'm slow, I like to understand things well, I hate competing, I don't get up at 6 am (but probably I won't even make them the same day), and rather than finish the puzzles i didn't do I'm writing the README.