Skip to content

LucasCzerny/AdventOfCode2024

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

78 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Advent of Code 2024 in C++

My happiness levels for each solution from 1-5:   🤨 😐 🙂 😀 😄

Part 1 Solution Part 2 Solution Notes
Day 01 part1.cpp - 0.253929ms - 😄 part2.cpp - 0.338325ms - 😄 hihi
Day 02 part1.cpp - 0.272486ms - 😄 part2.cpp - 0.445645ms - 😀 Kinda brute force-y but meh
Day 03 part1.cpp - 0.342503ms - 😄 part2.cpp - 0.906545ms - 😀 Def did not let chat gpt generate the regex
Day 04 part1.cpp - 0.239705ms - 😄 part2.cpp - 0.063468ms - 😄 Kinda brute force-y but meh
Day 05 part1.cpp - 1.099130ms - 🙂 part2.cpp - 2.204660ms - 🙂 Wasn't a huge fan of this day; part 2 is kinda scuffed because I'm using Bubble Sort lol
Day 06 part1.cpp - 0.597761ms - 😀 part2.cpp - 2504.730ms - 😐 Part 2 could def be better, there's no need to start from the starting position every time f.e.
Day 07 part1.cpp - 0.600864ms - 😀 part2.cpp - 16.03820ms - 🙂 Not too bad, could be optimized but I don't have the time
Day 08 part1.cpp - 0.064820ms - 😄 part2.cpp - 0.179963ms - 😄 Figured out how to use a custom Position struct with a set instead of std::pair
Day 09 part1.cpp - 0.109518ms - 😄 part2.cpp - 1204.123ms - 😐 tfw when the datatype for the checksum is too small and you spend 30min figuring out why your answer is wrong
Day 10 part1.cpp - 1.292020ms - 😄 part2.cpp - 0.563295ms - 😄 Solved part2 before part2
Day 11 part1.cpp - 0.691646ms - 😀 part2.cpp - 23.68010ms - 😀 me rn

 

Advent of Code 2024 Art

How to run

NOTE: I am using C++20 with gcc version 15.0.0 (built from source). It might not compile on other compilers.

cmake

Run the following commands to build the executables:

mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
make

Then, run them with:

./Part1

or

./Part2

For VsCode users

  • Install the CMake extensions
  • Open the Day xx folder in VsCode
  • Run CMake: Configure if it's not already configured
  • You can set the target (part1 or part2) with CMake: Set Launch/Debug Target
  • If you want to switch between Debug and Release mode, run CMake: Select Variant
  • Press Shift+F5 to run

Notes

Each Day xx folder consists of the following files:

  • part[1,2].cpp: The code for each part

  • output_part[1,2].txt: The output for the each part

  • sample_input.txt: The sample input given in the task description

    OR sample_input_part[1,2].txt if there are multiple sample inputs given

  • CMakeLists.txt: The CMake build instructions

There is also a lib folder at the root of the repository with utility functions like read_file() and average_time() for timing.

Note that I'm using std::chrono::high_resolution_clock, which, despite it's name, is not very accurate (it usually just uses the system clock, but it depends on the implementation). It's also going to vary due to interrupts and task switches. For the first couple of days where the execution time is < 1ms, the timer isn't that useful. However, I still think it's going to be a nice estimate for the later days.

About

Advent of Code 2024 in C++

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published