Compare commits

..

7 Commits

Author SHA1 Message Date
7886c985e1 Add d2p1 to cmake + d2p1 parsing 2025-12-02 18:39:59 -05:00
233a5f4e0f d1p2 faf done 2025-12-01 17:04:38 -05:00
11d45e0f65 Fix typo in README.md 2025-12-01 16:33:31 -05:00
122ca3af3d Clean up directory 2025-12-01 16:32:51 -05:00
bf31fa0de5 Remove cmake test 2025-12-01 16:31:34 -05:00
28223c0385 Update build commands in README.md 2025-12-01 16:26:42 -05:00
9a644f0ea3 Add README.md 2025-12-01 16:24:45 -05:00
13 changed files with 318 additions and 115 deletions

1
.idea/.name generated Normal file
View File

@@ -0,0 +1 @@
AdventOfCode2025

97
.idea/editor.xml generated
View File

@@ -244,102 +244,5 @@
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=IfStdIsConstantEvaluatedCanBeReplaced/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=StdIsConstantEvaluatedWillAlwaysEvaluateToConstant/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=StringLiteralTypo/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppClangFormat/EnableClangFormatSupport/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_ARGUMENT/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_BINARY_EXPRESSIONS_CHAIN/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_CALLS_CHAIN/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_EXPRESSION/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_EXTENDS_LIST/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_FOR_STMT/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_PARAMETER/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_TYPE_ARGUMENT/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_TYPE_PARAMETER/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTIPLE_DECLARATION/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_TERNARY/@EntryValue" value="ALIGN_ALL" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ANONYMOUS_METHOD_DECLARATION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BLANK_LINES_AROUND_CLASS_DEFINITION/@EntryValue" value="1" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BLANK_LINES_AROUND_DECLARATIONS/@EntryValue" value="0" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BLANK_LINES_AROUND_FUNCTION_DECLARATION/@EntryValue" value="1" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BLANK_LINES_AROUND_FUNCTION_DEFINITION/@EntryValue" value="1" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BREAK_TEMPLATE_DECLARATION/@EntryValue" value="LINE_BREAK" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/CASE_BLOCK_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/CONTINUOUS_LINE_INDENT/@EntryValue" value="Double" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/FREE_BLOCK_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_ACCESS_SPECIFIERS_FROM_CLASS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_CASE_FROM_SWITCH/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_CLASS_MEMBERS_FROM_ACCESS_SPECIFIERS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_COMMENT/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_SIZE/@EntryValue" value="4" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_STYLE/@EntryValue" value="Space" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INITIALIZER_BRACES/@EntryValue" value="END_OF_LINE_NO_SPACE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INT_ALIGN_EQ/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INVOCABLE_DECLARATION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/KEEP_BLANK_LINES_IN_CODE/@EntryValue" value="2" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/KEEP_BLANK_LINES_IN_DECLARATIONS/@EntryValue" value="2" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/KEEP_USER_LINEBREAKS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/LINE_BREAK_AFTER_COLON_IN_MEMBER_INITIALIZER_LISTS/@EntryValue" value="ON_SINGLE_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/MEMBER_INITIALIZER_LIST_STYLE/@EntryValue" value="DO_NOT_CHANGE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/NAMESPACE_DECLARATION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/NAMESPACE_INDENTATION/@EntryValue" value="All" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/OTHER_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/PLACE_CATCH_ON_NEW_LINE/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/PLACE_ELSE_ON_NEW_LINE/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/PLACE_NAMESPACE_DEFINITIONS_ON_SAME_LINE/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/PLACE_WHILE_ON_NEW_LINE/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SIMPLE_BLOCK_STYLE/@EntryValue" value="DO_NOT_CHANGE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_CAST_EXPRESSION_PARENTHESES/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_COLON_IN_BITFIELD_DECLARATOR/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_COMMA_IN_TEMPLATE_ARGS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_COMMA_IN_TEMPLATE_PARAMS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_EXTENDS_COLON/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_FOR_COLON/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_FOR_SEMICOLON/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_PTR_IN_DATA_MEMBER/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_PTR_IN_DATA_MEMBERS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_PTR_IN_METHOD/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_PTR_IN_NESTED_DECLARATOR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_REF_IN_DATA_MEMBER/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_REF_IN_DATA_MEMBERS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_REF_IN_METHOD/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_UNARY_OPERATOR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_COLON_IN_BITFIELD_DECLARATOR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_EXTENDS_COLON/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_FOR_COLON/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_FOR_SEMICOLON/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_PTR_IN_ABSTRACT_DECL/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_PTR_IN_DATA_MEMBER/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_PTR_IN_DATA_MEMBERS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_PTR_IN_METHOD/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_REF_IN_ABSTRACT_DECL/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_REF_IN_DATA_MEMBER/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_REF_IN_DATA_MEMBERS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_REF_IN_METHOD/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_TEMPLATE_ARGS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_TEMPLATE_PARAMS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BETWEEN_CLOSING_ANGLE_BRACKETS_IN_TEMPLATE_ARGS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_ARRAY_ACCESS_BRACKETS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_CAST_EXPRESSION_PARENTHESES/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_DECLARATION_PARENTHESES/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_EMPTY_BLOCKS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_EMPTY_INITIALIZER_BRACES/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_EMPTY_METHOD_PARENTHESES/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_EMPTY_TEMPLATE_PARAMS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_INITIALIZER_BRACES/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_TEMPLATE_ARGS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_TEMPLATE_PARAMS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPECIAL_ELSE_IF_TREATMENT/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/TAB_WIDTH/@EntryValue" value="4" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/TYPE_DECLARATION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_AFTER_BINARY_OPSIGN/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_AFTER_DECLARATION_LPAR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_AFTER_INVOCATION_LPAR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_ARGUMENTS_STYLE/@EntryValue" value="WRAP_IF_LONG" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_DECLARATION_LPAR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_DECLARATION_RPAR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_INVOCATION_LPAR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_INVOCATION_RPAR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_TERNARY_OPSIGNS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_PARAMETERS_STYLE/@EntryValue" value="WRAP_IF_LONG" type="string" />
<option name="/Default/CodeStyle/EditorConfig/EnableClangFormatSupport/@EntryValue" value="false" type="bool" />
</component>
</project>

View File

@@ -27,12 +27,14 @@ include_directories(src/common)
### EXECUTABLES
# Exe to make sure cmake is working
add_executable(testcmake src/testcmake/main.cpp)
### Day 1
# P1
add_executable(d1p1 src/day1/p1/main.cpp)
add_executable(d1p1-faf src/day1/p1/faf.cpp)
add_executable(d1p1 src/day1/p1.cpp)
add_executable(d1p1-faf src/day1/p1-faf.cpp)
# P2
add_executable(d1p2 src/day1/p2/main.cpp)
add_executable(d1p2 src/day1/p2.cpp)
add_executable(d1p2-faf src/day1/p2-faf.cpp)
### Day 2
# P1
add_executable(d2p1 src/day2/p1.cpp)

57
README.md Normal file
View File

@@ -0,0 +1,57 @@
# Advent of Code 2025
https://adventofcode.com/2025
## Building
Everything is handled by cmake which most ide's can handle.
Make sure you have a compiler (MSVC or GCC), CMake, and make/ninja installed.
If you're using make to build the project, run the following commands:
1. `mkdir build`
2. `cd build`
3. `cmake .. -DCMAKE_BUILD_TYPE=Release -G "Unix Makefiles"`
4. `make -j <number of threads>`
If you're using ninja to build the project, run the following commands:
1. `mkdir build`
2. `cd build`
3. `cmake .. -DCMAKE_BUILD_TYPE=Release -G Ninja`
4. `ninja`
## Directory structure
- `src`: Contains the source code for each day.
- `src/common`: Contains some generalized headers that are used by multiple days.
- `src/dayX`: Contains the source code for day `X`
- `src/dayx/pY`: Contains the source code for part `Y` of day `X`
- `input`: Contains the input for each day.
## Types
During this challenge, I plan to have multiple different
types of solutions.
- Normal: A more "normal" solution, opting for more readable code without doing anything fancy.
- Faf: The fastest solution I can think of.
Each solution has its own executable following the following naming convention: `dXpY-type`. Where `X` is the day number, `pY` is the part number, and `type` is the type of solution (Normal omits the type all together Ex: a normal day1 part1 executable would be `d1p1`).
## Benchmarks
All benchmarks are running using the timer class defined in `src/common/timer.h`. <br>
"Normal" solutions are only run once, as they aren't designed to be as fast as possible.<br>
"Faf" solutions are run multiple times to get a more accurate average.<br>
All benchmarks and iterations include file IO, mostly because everything calculates within single digit microseconds or less.
All benchmarks are run on a system with the following specs:
- CPU: AMD Ryzen 9 8945HS
- RAM: 32GB DDR5 6000MHz
- SSD: Samsung 990 Pro
- OS: Windows 11 24H2
- Compiler: gcc version 13.2.0 (x86_64-posix-seh-rev0, Built by MinGW-Builds project)
| Day | Part | Type | Time (us) | Iterations |
|-----|------|--------|-----------|------------|
| 1 | 1 | faf | 43 | 100000 |
| 1 | 1 | Normal | 483 | 1 |
| 1 | 2 | Normal | 472 | 1 |
| 1 | 2 | faf | 44 | 100000 |

3
input/day2/p1-test.txt Normal file
View File

@@ -0,0 +1,3 @@
11-22,95-115,998-1012,1188511880-1188511890,222220-222224,
1698522-1698528,446443-446449,38593856-38593862,565653-565659,
824824821-824824827,2121212118-2121212124

1
input/day2/p1.txt Normal file
View File

@@ -0,0 +1 @@
9226466333-9226692707,55432-96230,4151-6365,686836-836582,519296-634281,355894-471980,971626-1037744,25107-44804,15139904-15163735,155452-255998,2093-4136,829776608-829880425,4444385616-4444502989,2208288-2231858,261-399,66-119,91876508-91956018,2828255673-2828317078,312330-341840,6464-10967,5489467-5621638,1-18,426-834,3434321102-3434378477,4865070-4972019,54475091-54592515,147-257,48664376-48836792,45-61,1183-1877,24-43

View File

@@ -30,7 +30,7 @@ public:
for (const auto &[name, time] : points) {
std::cout << "\t" << name << ": " << std::chrono::duration_cast<std::chrono::milliseconds>(time - start).count() << " ms | " << std::chrono::duration_cast<std::chrono::microseconds>(time - start).count() << " us" << std::endl;
}
std::cout << "Global: " << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() / iterations << " ms | " << std::chrono::duration_cast<std::chrono::microseconds>(end-start).count() / iterations << " us" << std::endl;
std::cout << "Global (" << iterations << "): " << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() / iterations << " ms | " << std::chrono::duration_cast<std::chrono::microseconds>(end-start).count() / iterations << " us" << std::endl;
}
private:

View File

@@ -66,7 +66,7 @@
#include "timer.h"
int main() {
constexpr int iterations = 1000;
constexpr int iterations = 100000;
Timer timer(iterations);
int password = 0;
@@ -79,7 +79,6 @@ int main() {
int state = 50;
const char* ptr = buffer.data();
const char* end = ptr + size;
@@ -87,9 +86,10 @@ int main() {
const bool is_right = (*ptr == 'R');
++ptr;
int number;
auto [next, ec] = std::from_chars(ptr, end, number);
ptr = next;
int number = 0;
while (ptr < end && *ptr >= '0' && *ptr <= '9') {
number = number * 10 + (*ptr++ - '0');
}
if (ptr < end && *ptr == '\r') ++ptr;
if (ptr < end && *ptr == '\n') ++ptr;

149
src/day1/p2-faf.cpp Normal file
View File

@@ -0,0 +1,149 @@
//--- Day 1: Secret Entrance ---
// The Elves have good news and bad news.
//
// The good news is that they've discovered project management! This has given them the tools they need to prevent their usual Christmas emergency. For example, they now know that the North Pole decorations need to be finished soon so that other critical tasks can start on time.
//
// The bad news is that they've realized they have a different emergency: according to their resource planning, none of them have any time left to decorate the North Pole!
//
// To save Christmas, the Elves need you to finish decorating the North Pole by December 12th.
//
// Collect stars by solving puzzles. Two puzzles will be made available on each day; the second puzzle is unlocked when you complete the first. Each puzzle grants one star. Good luck!
//
// You arrive at the secret entrance to the North Pole base ready to start decorating. Unfortunately, the password seems to have been changed, so you can't get in. A document taped to the wall helpfully explains:
//
// "Due to new security protocols, the password is locked in the safe below. Please see the attached document for the new combination."
//
// The safe has a dial with only an arrow on it; around the dial are the numbers 0 through 99 in order. As you turn the dial, it makes a small click noise as it reaches each number.
//
// The attached document (your puzzle input) contains a sequence of rotations, one per line, which tell you how to open the safe. A rotation starts with an L or R which indicates whether the rotation should be to the left (toward lower numbers) or to the right (toward higher numbers). Then, the rotation has a distance value which indicates how many clicks the dial should be rotated in that direction.
//
// So, if the dial were pointing at 11, a rotation of R8 would cause the dial to point at 19. After that, a rotation of L19 would cause it to point at 0.
//
// Because the dial is a circle, turning the dial left from 0 one click makes it point at 99. Similarly, turning the dial right from 99 one click makes it point at 0.
//
// So, if the dial were pointing at 5, a rotation of L10 would cause it to point at 95. After that, a rotation of R5 could cause it to point at 0.
//
// The dial starts by pointing at 50.
//
// You could follow the instructions, but your recent required official North Pole secret entrance security training seminar taught you that the safe is actually a decoy. The actual password is the number of times the dial is left pointing at 0 after any rotation in the sequence.
//
// For example, suppose the attached document contained the following rotations:
//
// L68
// L30
// R48
// L5
// R60
// L55
// L1
// L99
// R14
// L82
//
// Following these rotations would cause the dial to move as follows:
//
// The dial starts by pointing at 50.
// The dial is rotated L68 to point at 82.
// The dial is rotated L30 to point at 52.
// The dial is rotated R48 to point at 0.
// The dial is rotated L5 to point at 95.
// The dial is rotated R60 to point at 55.
// The dial is rotated L55 to point at 0.
// The dial is rotated L1 to point at 99.
// The dial is rotated L99 to point at 0.
// The dial is rotated R14 to point at 14.
// The dial is rotated L82 to point at 32.
//
// Because the dial points at 0 a total of three times during this process, the password in this example is 3.
//
// Analyze the rotations in your attached document. What's the actual password to open the door?
/// Dev note: See src/day1/p1/main.cpp
// --- Part Two ---
//
// You're sure that's the right password, but the door won't open. You knock, but nobody answers. You build a snowman while you think.
//
// As you're rolling the snowballs for your snowman, you find another security document that must have fallen into the snow:
//
// "Due to newer security protocols, please use password method 0x434C49434B until further notice."
//
// You remember from the training seminar that "method 0x434C49434B" means you're actually supposed to count the number of times any click causes the dial to point at 0, regardless of whether it happens during a rotation or at the end of one.
//
// Following the same rotations as in the above example, the dial points at zero a few extra times during its rotations:
//
// The dial starts by pointing at 50.
// The dial is rotated L68 to point at 82; during this rotation, it points at 0 once.
// The dial is rotated L30 to point at 52.
// The dial is rotated R48 to point at 0.
// The dial is rotated L5 to point at 95.
// The dial is rotated R60 to point at 55; during this rotation, it points at 0 once.
// The dial is rotated L55 to point at 0.
// The dial is rotated L1 to point at 99.
// The dial is rotated L99 to point at 0.
// The dial is rotated R14 to point at 14.
// The dial is rotated L82 to point at 32; during this rotation, it points at 0 once.
//
// In this example, the dial points at 0 three times at the end of a rotation, plus three more times during a rotation. So, in this example, the new password would be 6.
//
// Be careful: if the dial were pointing at 50, a single rotation like R1000 would cause the dial to point at 0 ten times before returning back to 50!
//
// Using password method 0x434C49434B, what is the password to open the door?
#include <iostream>
#include <string>
#include <fstream>
#include "timer.h"
int main() {
constexpr int iterations = 100000;
Timer timer(iterations);
int password = 0;
for (int i = 0; i < iterations; ++i) {
std::ifstream stream("input/day1/p1.txt", std::ios::binary | std::ios::ate);
const auto size = stream.tellg();
stream.seekg(0);
std::vector<char> buffer(size);
stream.read(buffer.data(), size);
int state = 50;
const char* ptr = buffer.data();
const char* end = ptr + size;
while (ptr < end) {
const bool is_right = (*ptr == 'R');
++ptr;
int number = 0;
while (ptr < end && *ptr >= '0' && *ptr <= '9') {
number = number * 10 + (*ptr++ - '0');
}
if (ptr < end && *ptr == '\r') ++ptr;
if (ptr < end && *ptr == '\n') ++ptr;
password = password + (number / 100);
const int remainder = number % 100;
int new_state;
if (is_right) {
if (remainder >= (100 - state)) { password++; }
new_state = (state + remainder) % 100;
} else {
if (state != 0 && remainder >= state) { password++; }
new_state = (state - remainder) % 100;
if (new_state < 0) { new_state += 100; }
}
state = new_state;
}
}
timer.stop();
std::cout << "Password: " << password / iterations << std::endl;
timer.print();
return 0;
}

93
src/day2/p1.cpp Normal file
View File

@@ -0,0 +1,93 @@
//
// --- Day 2: Gift Shop ---
//
// You get inside and take the elevator to its only other stop: the gift shop.
// "Thank you for visiting the North Pole!" gleefully exclaims a nearby sign.
// You aren't sure who is even allowed to visit the North Pole, but you know you
// can access the lobby through here, and from there you can access the rest of the North Pole base.
//
// As you make your way through the surprisingly extensive selection, one of
// the clerks recognizes you and asks for your help.
//
// As it turns out, one of the younger Elves was playing on a gift shop computer
// and managed to add a whole bunch of invalid product IDs to their gift shop database!
// Surely, it would be no trouble for you to identify the invalid product IDs for them, right?
//
// They've even checked most of the product ID ranges already; they only have
// a few product ID ranges (your puzzle input) that you'll need to check. For example:
//
// 11-22,95-115,998-1012,1188511880-1188511890,222220-222224,
// 1698522-1698528,446443-446449,38593856-38593862,565653-565659,
// 824824821-824824827,2121212118-2121212124
//
// (The ID ranges are wrapped here for legibility; in your input, they
// appear on a single long line.)
//
// The ranges are separated by commas (,); each range gives its
// first ID and last ID separated by a dash (-).
//
// Since the young Elf was just doing silly patterns, you can find the invalid IDs
// by looking for any ID which is made only of some sequence of digits repeated twice.
// So, 55 (5 twice), 6464 (64 twice), and 123123 (123 twice) would all be invalid IDs.
//
// None of the numbers have leading zeroes; 0101 isn't an ID at all. (101 is a
// valid ID that you would ignore.)
//
// Your job is to find all of the invalid IDs that appear in the given ranges.
// In the above example:
//
// 11-22 has two invalid IDs, 11 and 22.
// 95-115 has one invalid ID, 99.
// 998-1012 has one invalid ID, 1010.
// 1188511880-1188511890 has one invalid ID, 1188511885.
// 222220-222224 has one invalid ID, 222222.
// 1698522-1698528 contains no invalid IDs.
// 446443-446449 has one invalid ID, 446446.
// 38593856-38593862 has one invalid ID, 38593859.
// The rest of the ranges contain no invalid IDs.
//
// Adding up all the invalid IDs in this example produces 1227775554.
//
// What do you get if you add up all of the invalid IDs?
#include <iostream>
#include <fstream>
#include "timer.h"
std::tuple<std::vector<char>, std::streampos> read_input(std::string filename) {
std::ifstream stream(filename, std::ios::binary | std::ios::ate);
const auto size = stream.tellg();
stream.seekg(0);
std::vector<char> buffer(size);
stream.read(buffer.data(), size);
stream.close();
return {buffer, size};
}
std::vector<std::string> solve(std::vector<char>* input_data, std::streampos size) {
const char* ptr = input_data->data();
const char* end = ptr + size;
while (ptr < end) {
// Get range
std::vector<char> range;
while (ptr < end) {
}
}
}
int main() {
Timer timer;
std::tuple<std::vector<char>, std::streampos> input_data = read_input("input/day2/p1.txt");
timer.add_point("File read");
std::vector<std::string> ranges = solve(&std::get<0>(input_data), std::get<1>(input_data));
timer.add_point("Solve");
timer.stop();
timer.print();
}

View File

@@ -1,6 +0,0 @@
#include <iostream>
int main() {
std::cout << "Compiles!" << std::endl;
return 0;
}