feat(2024/01): Init puzzle
This commit is contained in:
parent
9ffcca2f87
commit
807fda4356
14
01/.editorconfig
Normal file
14
01/.editorconfig
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
# EditorConfig is awesome: https://EditorConfig.org
|
||||||
|
|
||||||
|
# Project files
|
||||||
|
# Matches multiple files with brace expansion notation
|
||||||
|
[*.{c,h,cc}]
|
||||||
|
|
||||||
|
# Set charset
|
||||||
|
charset = utf-8
|
||||||
|
max_line_length = 80
|
||||||
|
|
||||||
|
# 2 space indentation
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 2
|
||||||
|
|
82
01/.gitignore
vendored
Normal file
82
01/.gitignore
vendored
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
# ClangD
|
||||||
|
.cache
|
||||||
|
|
||||||
|
# Nix files
|
||||||
|
.direnv
|
||||||
|
|
||||||
|
# Prerequisites
|
||||||
|
*.d
|
||||||
|
|
||||||
|
# Object files
|
||||||
|
*.o
|
||||||
|
*.ko
|
||||||
|
*.obj
|
||||||
|
*.elf
|
||||||
|
|
||||||
|
# Linker output
|
||||||
|
*.ilk
|
||||||
|
*.map
|
||||||
|
*.exp
|
||||||
|
|
||||||
|
# Precompiled Headers
|
||||||
|
*.gch
|
||||||
|
*.pch
|
||||||
|
|
||||||
|
# Libraries
|
||||||
|
*.lib
|
||||||
|
*.a
|
||||||
|
*.la
|
||||||
|
*.lo
|
||||||
|
|
||||||
|
# Shared objects (inc. Windows DLLs)
|
||||||
|
*.dll
|
||||||
|
*.so
|
||||||
|
*.so.*
|
||||||
|
*.dylib
|
||||||
|
|
||||||
|
# Executables
|
||||||
|
*.exe
|
||||||
|
*.out
|
||||||
|
*.app
|
||||||
|
*.i*86
|
||||||
|
*.x86_64
|
||||||
|
*.hex
|
||||||
|
|
||||||
|
# Debug files
|
||||||
|
*.dSYM/
|
||||||
|
*.su
|
||||||
|
*.idb
|
||||||
|
*.pdb
|
||||||
|
|
||||||
|
# Kernel Module Compile Results
|
||||||
|
*.mod*
|
||||||
|
*.cmd
|
||||||
|
.tmp_versions/
|
||||||
|
modules.order
|
||||||
|
Module.symvers
|
||||||
|
Mkfile.old
|
||||||
|
dkms.conf
|
||||||
|
|
||||||
|
# Vscode
|
||||||
|
.vscode/
|
||||||
|
|
||||||
|
# CMake
|
||||||
|
CMakeLists.txt.user
|
||||||
|
CMakeCache.txt
|
||||||
|
CMakeFiles
|
||||||
|
CMakeScripts
|
||||||
|
Testing
|
||||||
|
Makefile
|
||||||
|
cmake_install.cmake
|
||||||
|
install_manifest.txt
|
||||||
|
compile_commands.json
|
||||||
|
.cache/
|
||||||
|
CTestTestfile.cmake
|
||||||
|
_deps
|
||||||
|
build/
|
||||||
|
output/
|
||||||
|
|
||||||
|
lib/
|
||||||
|
bin/
|
||||||
|
*.swp
|
||||||
|
|
52
01/CMakeLists.txt
Normal file
52
01/CMakeLists.txt
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.14)
|
||||||
|
# Generate compile_commands.json
|
||||||
|
set(PROJECT_NAME CTemplate)
|
||||||
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
|
|
||||||
|
# Turn on testing by default
|
||||||
|
option(BUILD_TESTING "Build tests" ON)
|
||||||
|
# Turn off documentation build by default
|
||||||
|
option(BUILD_DOC "Build documentation" OFF)
|
||||||
|
# Turn off coverage by default
|
||||||
|
option(ENABLE_COVERAGE "Enable test coverage" ON)
|
||||||
|
|
||||||
|
# Set C standard to C99
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
|
||||||
|
set(CMAKE_C_FLAGS_DEBUG "-std=c99 -Wall -Wextra -Wunreachable-code -g -O0")
|
||||||
|
|
||||||
|
# Set the project name and version number. This allows for a user of your
|
||||||
|
project(${PROJECT_NAME} VERSION 0.1)
|
||||||
|
set(${PROJECT_NAME} 0.1)
|
||||||
|
|
||||||
|
# Function to prepend the subdirectory to source files in subdirectories
|
||||||
|
FUNCTION(PREPEND var )
|
||||||
|
SET(listVar "")
|
||||||
|
FOREACH(f ${${var}})
|
||||||
|
LIST(APPEND listVar "${CMAKE_CURRENT_SOURCE_DIR}/${f}")
|
||||||
|
ENDFOREACH(f)
|
||||||
|
SET(${var} "${listVar}" PARENT_SCOPE)
|
||||||
|
ENDFUNCTION(PREPEND)
|
||||||
|
|
||||||
|
# Include source code and headers. This calls the CMakeLists.txt in each
|
||||||
|
# subdirectory. These can define their own libraries, executables, etc. as targets,
|
||||||
|
# but here we define all exportable targets in the root CMakeLists.txt.
|
||||||
|
add_subdirectory(src)
|
||||||
|
add_subdirectory(include)
|
||||||
|
|
||||||
|
# enable unit testing via "make test" once the code has been compiled.
|
||||||
|
# TODO: Google Test
|
||||||
|
|
||||||
|
if(BUILD_TESTING)
|
||||||
|
message("Testing enabled")
|
||||||
|
enable_testing()
|
||||||
|
add_subdirectory(tests)
|
||||||
|
target_include_directories(tests PRIVATE include)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Add PROJECT_NAME as an executable target.
|
||||||
|
add_executable(${PROJECT_NAME} ${SRC} ${INC})
|
||||||
|
target_include_directories(${PROJECT_NAME} PRIVATE include)
|
||||||
|
|
||||||
|
if(BUILD_DOC)
|
||||||
|
add_subdirectory(docs)
|
||||||
|
endif()
|
88
01/README.md
Normal file
88
01/README.md
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
# Day 1: Historian Hysteria
|
||||||
|
|
||||||
|
[https://adventofcode.com/2024/day/1](https://adventofcode.com/2024/day/1)
|
||||||
|
|
||||||
|
## Description
|
||||||
|
|
||||||
|
### Part One
|
||||||
|
|
||||||
|
#### Intro
|
||||||
|
|
||||||
|
The _Chief Historian_ is always present for the big Christmas sleigh launch,
|
||||||
|
but nobody has seen him in months!
|
||||||
|
Last anyone heard, he was visiting locations that are historically significant to the North Pole;
|
||||||
|
a group of Senior Historians has asked you to accompany them as they check the
|
||||||
|
places they think he was most likely to visit.
|
||||||
|
|
||||||
|
As each location is checked, they will mark it on their list with a _star_.
|
||||||
|
They figure the Chief Historian _must_ be in one of the first fifty places they'll look,
|
||||||
|
so in order to save Christmas, you need to help them get _fifty stars_ on their
|
||||||
|
list before Santa takes off on December 25th.
|
||||||
|
|
||||||
|
Collect stars by solving puzzles.
|
||||||
|
Two puzzles will be made available on each day in the Advent calendar;
|
||||||
|
the second puzzle is unlocked when you complete the first.
|
||||||
|
Each puzzle grants _one star_. Good luck!
|
||||||
|
|
||||||
|
#### Assignment
|
||||||
|
|
||||||
|
You haven't even left yet and the group of Elvish Senior Historians has already hit a problem:
|
||||||
|
their list of locations to check is currently _empty_.
|
||||||
|
Eventually, someone decides that the best place to check first would be the Chief Historian's office.
|
||||||
|
|
||||||
|
Upon pouring into the office, everyone confirms that the Chief Historian is
|
||||||
|
ndeed nowhere to be found. Instead, the Elves discover an assortment of notes and
|
||||||
|
lists of historically significant locations!
|
||||||
|
his seems to be the planning the Chief Historian was doing before he left.
|
||||||
|
Perhaps these notes can be used to determine which locations to search?
|
||||||
|
|
||||||
|
Throughout the Chief's office, the historically significant locations are listed
|
||||||
|
not by name but by a unique number called the _location ID_.
|
||||||
|
To make sure they don't miss anything, The Historians split into two groups,
|
||||||
|
each searching the office and trying to create their own complete list of location IDs.
|
||||||
|
|
||||||
|
There's just one problem: by holding the two lists up _side by side_ (your puzzle input),
|
||||||
|
it quickly becomes clear that the lists aren't very similar.
|
||||||
|
Maybe you can help The Historians reconcile their lists?
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
```
|
||||||
|
3 4
|
||||||
|
4 3
|
||||||
|
2 5
|
||||||
|
1 3
|
||||||
|
3 9
|
||||||
|
3 3
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
Maybe the lists are only off by a small amount!
|
||||||
|
To find out, pair up the numbers and measure how far apart they are.
|
||||||
|
Pair up the _smallest number in the left list_ with the _smallest number in the right list_,
|
||||||
|
then the _second-smallest left number_ with the _second-smallest right number_, and so on.
|
||||||
|
|
||||||
|
Within each pair, figure out _how far apart_ the two numbers are; you'll need to
|
||||||
|
_add up all of those distances_.
|
||||||
|
For example, if you pair up a `3` from the left list with a `7` from the right list,
|
||||||
|
the distance apart is `4`; if you pair up a `9` with a `3`, the distance apart is `6`.
|
||||||
|
|
||||||
|
In the example list above, the pairs and distances would be as follows:
|
||||||
|
|
||||||
|
- The smallest number in the left list is `1`, and the smallest number in the right list is `3`.
|
||||||
|
The distance between them is _`2`_.
|
||||||
|
- The second-smallest number in the left list is `2`,
|
||||||
|
and the second-smallest number in the right list is another `3`.
|
||||||
|
The distance between them is _`1`_.
|
||||||
|
- The third-smallest number in both lists is `3`, so the distance between them is _`0`_.
|
||||||
|
- The next numbers to pair up are `3` and `4`, a distance of _`1`_.
|
||||||
|
- The fifth-smallest numbers in each list are `3` and `5`, a distance of _`2`_.
|
||||||
|
- Finally, the largest number in the left list is `4`,
|
||||||
|
while the largest number in the right list is `9`; these are a distance _`5`_ apart.
|
||||||
|
|
||||||
|
To find the _total distance_ between the left list and the right list,
|
||||||
|
add up the distances between all of the pairs you found.
|
||||||
|
In the example above, this is `2 + 1 + 0 + 1 + 2 + 5`, a total distance of _`11`_!
|
||||||
|
|
||||||
|
Your actual left and right lists contain many location IDs.
|
||||||
|
_What is the total distance between your lists?_
|
20
01/docs/CMakeLists.txt
Normal file
20
01/docs/CMakeLists.txt
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
# check if Doxygen is installed
|
||||||
|
find_package(Doxygen)
|
||||||
|
if (DOXYGEN_FOUND)
|
||||||
|
# set input and output files
|
||||||
|
set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile)
|
||||||
|
set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
|
||||||
|
|
||||||
|
# request to configure the file
|
||||||
|
configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY)
|
||||||
|
message("Doxygen build started")
|
||||||
|
|
||||||
|
# note the option ALL which allows to build the docs together with the application
|
||||||
|
add_custom_target(doc ALL
|
||||||
|
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||||
|
COMMENT "Generating documentation with Doxygen"
|
||||||
|
VERBATIM )
|
||||||
|
else (DOXYGEN_FOUND)
|
||||||
|
message("Doxygen needs to be installed to generate the documentation")
|
||||||
|
endif (DOXYGEN_FOUND)
|
2826
01/docs/Doxyfile
Normal file
2826
01/docs/Doxyfile
Normal file
File diff suppressed because it is too large
Load Diff
16
01/include/CMakeLists.txt
Normal file
16
01/include/CMakeLists.txt
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
|
||||||
|
# Make an explicit list of all source files in IFJ23_INC. This is important
|
||||||
|
# because CMake is not a build system: it is a build system generator. Suppose
|
||||||
|
# you add a file foo.cpp to src/ after running cmake .. . If you set
|
||||||
|
# IFJ23_INC with `file(GLOB ... )`, this is not passed to the makefile; it
|
||||||
|
# doesn't know that foo.cpp exists and will not re-run cmake. Your
|
||||||
|
# collaborator's builds will fail and it will be unclear why. Whether you use
|
||||||
|
# file(GLOB ...) or not, you will need to re-run cmake, but with an explicit
|
||||||
|
# file list, you know beforehand why your code isn't compiling.
|
||||||
|
set(INC
|
||||||
|
)
|
||||||
|
|
||||||
|
# Form the full path to the source files...
|
||||||
|
PREPEND(INC)
|
||||||
|
# ... and pass the variable to the parent scope.
|
||||||
|
set(INC ${INC} PARENT_SCOPE)
|
1000
01/puzzle.input
Normal file
1000
01/puzzle.input
Normal file
File diff suppressed because it is too large
Load Diff
17
01/src/CMakeLists.txt
Normal file
17
01/src/CMakeLists.txt
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
|
||||||
|
# Make an explicit list of all source files in `CMakeDemo_SRC`. This is important
|
||||||
|
# because CMake is not a build system: it is a build system generator. Suppose
|
||||||
|
# you add a file foo.cpp to src/ after running cmake .. . If you set
|
||||||
|
# `CMakeDemo_SRC` with `file(GLOB ... )`, this is not passed to the makefile;
|
||||||
|
# the makefile doesn't know that foo.cpp exists and will not re-run cmake. Your
|
||||||
|
# collaborator's builds will fail and it will be unclear why. Whether you use
|
||||||
|
# file(GLOB ...) or not, you will need to re-run cmake, but with an explicit
|
||||||
|
# file list, you know beforehand why your code isn't compiling.
|
||||||
|
set(SRC
|
||||||
|
main.c
|
||||||
|
)
|
||||||
|
|
||||||
|
# Form the full path to the source files...
|
||||||
|
PREPEND(SRC)
|
||||||
|
# ... and pass the variable to the parent scope.
|
||||||
|
set(SRC ${SRC} PARENT_SCOPE)
|
25
01/src/main.c
Normal file
25
01/src/main.c
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
/**
|
||||||
|
* Copyright [2023] Jiří Štefka <jiriks74>
|
||||||
|
* Project: AdventOfCode
|
||||||
|
* @file main.c
|
||||||
|
* @brief Main entry point
|
||||||
|
* @author jiriks74
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Main entry point
|
||||||
|
* @param argc Number of command-line arguments.
|
||||||
|
* @param argv Array of command-line arguments.
|
||||||
|
*/
|
||||||
|
#ifndef TESTING
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
#endif
|
||||||
|
#ifdef TESTING
|
||||||
|
int main_test(int argc, char *argv[])
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
printf("Hello world!\n");
|
||||||
|
return 0;
|
||||||
|
}
|
83
01/tests/CMakeLists.txt
Normal file
83
01/tests/CMakeLists.txt
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
set(PROJECT_NAME ${PROJECT_NAME} PARENT_SCOPE )
|
||||||
|
# GoogleTest requires at least C++14
|
||||||
|
set(CMAKE_CXX_STANDARD 14)
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
|
# Get GoogleTest
|
||||||
|
include(FetchContent)
|
||||||
|
FetchContent_Declare(
|
||||||
|
googletest
|
||||||
|
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
|
||||||
|
)
|
||||||
|
# For Windows: Prevent overriding the parent project's compiler/linker settings
|
||||||
|
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
||||||
|
FetchContent_MakeAvailable(googletest)
|
||||||
|
|
||||||
|
add_subdirectory(src)
|
||||||
|
add_executable(tests ${TESTS})
|
||||||
|
|
||||||
|
# Link test executable against gtest & gtest_main
|
||||||
|
target_link_libraries(
|
||||||
|
tests
|
||||||
|
GTest::gtest_main
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(tests PRIVATE
|
||||||
|
${CMAKE_SOURCE_DIR}/src
|
||||||
|
)
|
||||||
|
|
||||||
|
# Discover tests
|
||||||
|
include(GoogleTest)
|
||||||
|
gtest_discover_tests(tests)
|
||||||
|
add_dependencies(tests ${PROJECT_NAME})
|
||||||
|
|
||||||
|
# The following section is inspired by https://github.com/cmake-modules/lcov
|
||||||
|
if(ENABLE_COVERAGE)
|
||||||
|
message("Test coverage enabled")
|
||||||
|
# set(exclude_dir "*/tests/* */_deps/* /usr/include/c++/11/**/* /usr/include/c++/**/*")
|
||||||
|
# set(exclude_dir "*/tests/* */_deps/* /usr/include/c++/11/tuple /usr/include/c++/11/**/*")
|
||||||
|
|
||||||
|
# Check for lcov, gcov and genhtml
|
||||||
|
find_program(GCOV gcov)
|
||||||
|
if (NOT GCOV)
|
||||||
|
message(WARNING "gcov not found")
|
||||||
|
endif()
|
||||||
|
find_program(LCOV lcov)
|
||||||
|
if (NOT LCOV)
|
||||||
|
message(WARNING "lcov not found")
|
||||||
|
endif()
|
||||||
|
find_program(GENHTML genhtml)
|
||||||
|
if (NOT GENHTML)
|
||||||
|
message(WARNING "genhtml not found")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (GCOV AND LCOV AND GENHTML)
|
||||||
|
# Set C compiler flags
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage -fprofile-arcs -ftest-coverage")
|
||||||
|
# Set C++ compiler flags
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage -fprofile-arcs -ftest-coverage")
|
||||||
|
|
||||||
|
set(covname cov.info)
|
||||||
|
add_custom_target(coverage DEPENDS ${covname})
|
||||||
|
add_dependencies(coverage tests ${PROJECT_NAME})
|
||||||
|
add_custom_command(
|
||||||
|
OUTPUT ${covname}
|
||||||
|
COMMAND rm -rf **/coverage
|
||||||
|
COMMAND ${LCOV} -c -o ${covname} -d ${CMAKE_BINARY_DIR}/tests/CMakeFiles/tests.dir/ -b . --gcov-tool ${GCOV}
|
||||||
|
COMMAND ${LCOV} -r ${covname} -o ${covname} "*/tests/*" "*/_deps/**/*" "/usr/include/c++/**/*" "/usr/include/c++/11/**/*"
|
||||||
|
COMMAND ${LCOV} -l ${covname}
|
||||||
|
COMMAND ${GENHTML} ${covname} -output coverage
|
||||||
|
COMMAND ${LCOV} -l ${covname} 2>/dev/null | grep Total | sed 's/|//g' | sed 's/Total://g' | awk '{print $1}' | sed s/%//g > coverage/total
|
||||||
|
COMMAND rm -rf CMakeFiles/tests.dir/src/*.gcda CMakeFiles/tests.dir/src/*.gcno
|
||||||
|
COMMAND rm -f ${covname}
|
||||||
|
)
|
||||||
|
set_directory_properties(PROPERTIES
|
||||||
|
ADDITIONAL_CLEAN_FILES ${covname}
|
||||||
|
)
|
||||||
|
set_directory_properties(PROPERTIES
|
||||||
|
ADDITIONAL_CLEAN_FILES coverage/
|
||||||
|
)
|
||||||
|
else()
|
||||||
|
message(WARNING "Cannot enable coverage. Missing the required tools")
|
||||||
|
endif()
|
||||||
|
endif()
|
17
01/tests/src/CMakeLists.txt
Normal file
17
01/tests/src/CMakeLists.txt
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
|
||||||
|
# Make an explicit list of all source files in `IFJ23_TESTS`. This is important
|
||||||
|
# because CMake is not a build system: it is a build system generator. Suppose
|
||||||
|
# you add a file foo.cpp to src/ after running cmake .. . If you set
|
||||||
|
# `IFJ23_TESTS` with `file(GLOB ... )`, this is not passed to the makefile;
|
||||||
|
# the makefile doesn't know that foo.cpp exists and will not re-run cmake. Your
|
||||||
|
# collaborator's builds will fail and it will be unclear why. Whether you use
|
||||||
|
# file(GLOB ...) or not, you will need to re-run cmake, but with an explicit
|
||||||
|
# file list, you know beforehand why your code isn't compiling.
|
||||||
|
set(TESTS
|
||||||
|
test.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
# Form the full path to the source files...
|
||||||
|
PREPEND(TESTS)
|
||||||
|
# ... and pass the variable to the parent scope.
|
||||||
|
set(TESTS ${TESTS} PARENT_SCOPE)
|
31
01/tests/src/test.cpp
Normal file
31
01/tests/src/test.cpp
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#define TESTING
|
||||||
|
|
||||||
|
// Include the source file(s) to be tested.
|
||||||
|
#include "main.c"
|
||||||
|
|
||||||
|
// Create a test fixture class template - this will be like a "conlection" of
|
||||||
|
// tests. the : public ::testing::Test part is important! Add it to your fixture
|
||||||
|
// class.
|
||||||
|
class HelloTest : public ::testing::Test {
|
||||||
|
HelloTest() {}
|
||||||
|
|
||||||
|
~HelloTest() {}
|
||||||
|
|
||||||
|
void SetUp() {}
|
||||||
|
|
||||||
|
void TearDown() {}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Add tests to the test fixture class.
|
||||||
|
// @param fixture_class_name The name of the test fixture class.
|
||||||
|
// @param test_name The name of the test.
|
||||||
|
TEST(HelloTest, BasicAssertions) {
|
||||||
|
// Execute the code to be tested.
|
||||||
|
// Expect two strings not to be equal.
|
||||||
|
EXPECT_STRNE("hello", "world");
|
||||||
|
// Expect equality.
|
||||||
|
EXPECT_EQ(7 * 6, 42);
|
||||||
|
}
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user