chore: Clean branch for 2024
This commit is contained in:
parent
17d14e61cc
commit
4b955506be
27 changed files with 0 additions and 7827 deletions
|
@ -1,14 +0,0 @@
|
|||
# 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
|
||||
|
74
01/.gitignore
vendored
74
01/.gitignore
vendored
|
@ -1,74 +0,0 @@
|
|||
# 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/
|
||||
lib/
|
||||
bin/
|
||||
*.swp
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
cmake_minimum_required(VERSION 3.14)
|
||||
# Generate compile_commands.json
|
||||
set(PROJECT_NAME 01)
|
||||
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()
|
55
01/README.md
55
01/README.md
|
@ -1,55 +0,0 @@
|
|||
# Day 1
|
||||
[link](https://adventofcode.com/2023/day/1)
|
||||
|
||||
## Assignment
|
||||
|
||||
### Day 1: Trebuchet?!
|
||||
|
||||
Something is wrong with global snow production,
|
||||
and you've been selected to take a look.
|
||||
The Elves have even given you a map;
|
||||
on it, they've used stars to mark the top fifty locations
|
||||
that are likely to be having problems.
|
||||
|
||||
You've been doing this long enough to know that to restore snow operations,
|
||||
you need to check all fifty stars by 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!
|
||||
|
||||
You try to ask why they can't just use a weather machine ("not powerful enough")
|
||||
and where they're even sending you ("the sky") and why your map looks mostly blank
|
||||
("you sure ask a lot of questions") and hang on did you just say the sky
|
||||
("of course, where do you think snow comes from") when you realize
|
||||
that the Elves are already loading you into a trebuchet
|
||||
("please hold still, we need to strap you in").
|
||||
|
||||
As they're making the final adjustments,
|
||||
they discover that their calibration document (your puzzle input)
|
||||
has been amended by a very young Elf who was apparently just excited to show off
|
||||
her art skills.
|
||||
Consequently, the Elves are having trouble reading the values on the document.
|
||||
|
||||
The newly-improved calibration document consists of lines of text;
|
||||
each line originally contained a specific calibration value
|
||||
that the Elves now need to recover.
|
||||
**On each line, the calibration value can be found by combining the first digit
|
||||
and the last digit (in that order) to form a single two-digit number.**
|
||||
|
||||
For example:
|
||||
|
||||
```example
|
||||
1abc2
|
||||
pqr3stu8vwx
|
||||
a1b2c3d4e5f
|
||||
treb7uchet
|
||||
```
|
||||
|
||||
In this example, the calibration values of these four lines are 12, 38, 15, and 77.
|
||||
Adding these together produces 142.
|
||||
|
||||
Consider your entire calibration document.
|
||||
What is the sum of all of the calibration values?
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
# 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
2826
01/docs/Doxyfile
File diff suppressed because it is too large
Load diff
|
@ -1,16 +0,0 @@
|
|||
|
||||
# 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)
|
1001
01/puzzle.input
1001
01/puzzle.input
File diff suppressed because it is too large
Load diff
|
@ -1,17 +0,0 @@
|
|||
|
||||
# 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)
|
122
01/src/main.c
122
01/src/main.c
|
@ -1,122 +0,0 @@
|
|||
/**
|
||||
* Copyright [2023] Jiří Štefka <jiriks74>
|
||||
* Project: AdventOfCode
|
||||
* @file main.c
|
||||
* @brief Main entry point
|
||||
* @author jiriks74
|
||||
*/
|
||||
#define _GNU_SOURCE
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/**
|
||||
* @brief Gets the first number in a string
|
||||
* param String where you want to find the number
|
||||
* return The first number found (or -1 if none found)
|
||||
* Gets the first number in a string. Can find numbers written as digits and
|
||||
* words.
|
||||
*/
|
||||
int getNum(const char *line) {
|
||||
char *str = (char *)line;
|
||||
// Mapping of words to numeric representations
|
||||
const char *numbers[] = {"zero", "one", "two", "three", "four",
|
||||
"five", "six", "seven", "eight", "nine"};
|
||||
const char *digits[] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};
|
||||
|
||||
// Find first written number
|
||||
char *smallestPos = strchr(str, *"\0");
|
||||
int numAtSmallPos = -1;
|
||||
for (int i = 0; i < sizeof(numbers) / sizeof(numbers[0]); i++) {
|
||||
char *pos = NULL;
|
||||
|
||||
char *written = strstr(str, numbers[i]);
|
||||
char *digit = strstr(str, digits[i]);
|
||||
|
||||
if (written == NULL && digit == NULL)
|
||||
continue;
|
||||
if (written == NULL)
|
||||
pos = digit;
|
||||
else if (digit == NULL)
|
||||
pos = written;
|
||||
else
|
||||
pos = digit < written ? digit : written;
|
||||
|
||||
if (pos < smallestPos) {
|
||||
numAtSmallPos = i;
|
||||
smallestPos = pos;
|
||||
}
|
||||
}
|
||||
|
||||
// Chen which was first and return it
|
||||
return numAtSmallPos;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets a calibration value from a line
|
||||
* @param char* line containing the calibration value
|
||||
* @return int the calibration value
|
||||
*/
|
||||
int getVal(const char *str) {
|
||||
int result = 0;
|
||||
int result2 = -1;
|
||||
for (int i = 0; i < strlen(str); i++) {
|
||||
int num = getNum(&str[i]);
|
||||
if (num >= 0) {
|
||||
if (result == 0) {
|
||||
result = num * 10;
|
||||
} else {
|
||||
result2 = num;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (result2 == -1) {
|
||||
result += result / 10;
|
||||
} else {
|
||||
result += result2;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Main entry point
|
||||
* @param argc Number of command-line arguments.
|
||||
* @param argv Array of command-line arguments.
|
||||
*/
|
||||
#ifdef TESTING
|
||||
int mainTest(FILE *stdin, int argc, char *argv[])
|
||||
#else
|
||||
int main(int argc, char *argv[])
|
||||
#endif
|
||||
{
|
||||
FILE *file;
|
||||
if (argc == 1) {
|
||||
file = stdin;
|
||||
} else {
|
||||
file = fopen(argv[1], "r"); // LCOV_EXCL_LINE
|
||||
}
|
||||
|
||||
// LCOV_EXCL_START
|
||||
if (file == NULL) {
|
||||
if (argc > 1)
|
||||
fprintf(stderr, "Could not open file '%s'\n", argv[1]);
|
||||
else
|
||||
fprintf(stderr, "Couldn't open file\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
// LCOV_EXCL_STOP
|
||||
|
||||
char *line = NULL;
|
||||
size_t len = 0;
|
||||
ssize_t read = 0;
|
||||
int result = 0;
|
||||
while ((read = getline(&line, &len, file) != -1)) {
|
||||
result += getVal(line);
|
||||
}
|
||||
|
||||
free(line);
|
||||
fclose(file);
|
||||
|
||||
printf("The sum of the calibration values is %d\n", result);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
|
@ -1,83 +0,0 @@
|
|||
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()
|
|
@ -1,17 +0,0 @@
|
|||
|
||||
# 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)
|
|
@ -1,81 +0,0 @@
|
|||
#include "gtest/gtest.h"
|
||||
#include <gtest/gtest.h>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
|
||||
#define TESTING
|
||||
|
||||
#include "main.c"
|
||||
|
||||
void stream_add(FILE *stream, std::string string) {
|
||||
fprintf(stream, "%s", string.c_str());
|
||||
fseek(stream, -string.length(), SEEK_CUR);
|
||||
}
|
||||
|
||||
class Trebuchet : public ::testing::Test {
|
||||
public:
|
||||
FILE *input;
|
||||
|
||||
Trebuchet() {}
|
||||
|
||||
~Trebuchet() {}
|
||||
|
||||
void SetUp() {
|
||||
input = tmpfile();
|
||||
if (input == NULL) {
|
||||
fprintf(stderr, "Error creating tmpfile\n");
|
||||
fprintf(stderr, "Error: %s\n", strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
void TearDown() {}
|
||||
};
|
||||
|
||||
TEST_F(Trebuchet, AssignmentInput) {
|
||||
testing::internal::CaptureStdout();
|
||||
stream_add(input, "1abc2\npqr3stu8vwx\na1b2c3d4e5f\ntreb7uchet");
|
||||
char *argv[2];
|
||||
mainTest(input, 1, argv);
|
||||
std::string output = testing::internal::GetCapturedStdout();
|
||||
// Check the output of the program.
|
||||
EXPECT_EQ("The sum of the calibration values is 142\n", output);
|
||||
}
|
||||
|
||||
TEST_F(Trebuchet, AssignmentInput2){
|
||||
testing::internal::CaptureStdout();
|
||||
stream_add(input, "two1nine\neightwothree\nabcone2threexyz\nxtwone3four\n4nineeightseven2\nzoneight234\n7pqrstsixteen");
|
||||
char *argv[2];
|
||||
mainTest(input, 1, argv);
|
||||
std::string output = testing::internal::GetCapturedStdout();
|
||||
// Check the output of the program.
|
||||
EXPECT_EQ("The sum of the calibration values is 281\n", output);
|
||||
}
|
||||
|
||||
TEST_F(Trebuchet, getVal) {
|
||||
EXPECT_EQ(12, getVal((char *)"1abc2"));
|
||||
EXPECT_EQ(38, getVal((char *)"pqr3stu8vwx"));
|
||||
EXPECT_EQ(15, getVal((char *)"a1b2c3d4e5f"));
|
||||
EXPECT_EQ(77, getVal((char *)"treb7uchet"));
|
||||
EXPECT_EQ(11, getVal((char *)"1"));
|
||||
}
|
||||
|
||||
TEST_F(Trebuchet, getNum) {
|
||||
EXPECT_EQ(0, getNum((char *)"zero"));
|
||||
EXPECT_EQ(1, getNum((char *)"one"));
|
||||
EXPECT_EQ(2, getNum((char *)"two"));
|
||||
EXPECT_EQ(3, getNum((char *)"three"));
|
||||
EXPECT_EQ(4, getNum((char *)"four"));
|
||||
EXPECT_EQ(5, getNum((char *)"five"));
|
||||
EXPECT_EQ(6, getNum((char *)"six"));
|
||||
EXPECT_EQ(7, getNum((char *)"seven"));
|
||||
EXPECT_EQ(8, getNum((char *)"eight"));
|
||||
EXPECT_EQ(9, getNum((char *)"nine"));
|
||||
|
||||
EXPECT_EQ(1, getNum((char *)"1"));
|
||||
EXPECT_EQ(1, getNum((char *)"one"));
|
||||
EXPECT_EQ(1, getNum((char *)"1two"));
|
||||
EXPECT_EQ(2, getNum((char *)"two1"));
|
||||
|
||||
EXPECT_EQ(1, getNum((char *)"1threeone"));
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
# 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
|
||||
|
64
02/.gitignore
vendored
64
02/.gitignore
vendored
|
@ -1,64 +0,0 @@
|
|||
# ClangD
|
||||
.cache
|
||||
|
||||
# Nix files
|
||||
.direnv
|
||||
|
||||
# Output folders
|
||||
output/
|
||||
|
||||
# Vimspector
|
||||
# .vimspector.json
|
||||
|
||||
# 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
|
|
@ -1,52 +0,0 @@
|
|||
cmake_minimum_required(VERSION 3.14)
|
||||
# Generate compile_commands.json
|
||||
set(PROJECT_NAME 02)
|
||||
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()
|
66
02/README.md
66
02/README.md
|
@ -1,66 +0,0 @@
|
|||
# Day 2
|
||||
[link](https://adventofcode.com/2023/day/2)
|
||||
|
||||
## Assignment
|
||||
|
||||
### Day 2: Cube Conundrum
|
||||
|
||||
You're launched high into the atmosphere!
|
||||
The apex of your trajectory just barely reaches the surface of a large island
|
||||
floating in the sky.
|
||||
You gently land in a fluffy pile of leaves.
|
||||
It's quite cold, but you don't see much snow.
|
||||
An Elf runs over to greet you.
|
||||
|
||||
The Elf explains that you've arrived
|
||||
at Snow Island and apologizes for the lack of snow.
|
||||
He'll be happy to explain the situation, but it's a bit of a walk,
|
||||
so you have some time.
|
||||
They don't get many visitors up here; would you like to play a game in the meantime?
|
||||
|
||||
As you walk, the Elf shows you a small bag and some cubes which are either red,
|
||||
green, or blue.
|
||||
Each time you play this game,
|
||||
he will hide a secret number of cubes of each color in the bag,
|
||||
and your goal is to figure out information about the number of cubes.
|
||||
|
||||
To get information, once a bag has been loaded with cubes,
|
||||
the Elf will reach into the bag, grab a handful of random cubes,
|
||||
show them to you, and then put them back in the bag.
|
||||
He'll do this a few times per game.
|
||||
|
||||
You play several games and record the information from each game (your puzzle input).
|
||||
Each game is listed with its ID number (like the 11 in Game 11: ...)
|
||||
followed by a semicolon-separated list of subsets of cubes that were revealed
|
||||
from the bag (like 3 red, 5 green, 4 blue).
|
||||
|
||||
For example, the record of a few games might look like this:
|
||||
|
||||
```example
|
||||
Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green
|
||||
Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue
|
||||
Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red
|
||||
Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red
|
||||
Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green
|
||||
```
|
||||
|
||||
In game 1, three sets of cubes are revealed from the bag (and then put back again).
|
||||
The first set is 3 blue cubes and 4 red cubes;
|
||||
the second set is 1 red cube, 2 green cubes, and 6 blue cubes;
|
||||
the third set is only 2 green cubes.
|
||||
|
||||
The Elf would first like to know which games would have been possible
|
||||
if the bag contained only 12 red cubes, 13 green cubes, and 14 blue cubes?
|
||||
|
||||
In the example above, games 1, 2, and 5 would have been possible
|
||||
if the bag had been loaded with that configuration.
|
||||
However, game 3 would have been impossible because at one point
|
||||
the Elf showed you 20 red cubes at once;
|
||||
similarly, game 4 would also have been impossible because the Elf
|
||||
showed you 15 blue cubes at once.
|
||||
If you add up the IDs of the games that would have been possible, you get 8.
|
||||
|
||||
Determine which games would have been possible
|
||||
if the bag had been loaded with only 12 red cubes, 13 green cubes, and 14 blue cubes.
|
||||
What is the sum of the IDs of those games?
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
# 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
02/docs/Doxyfile
2826
02/docs/Doxyfile
File diff suppressed because it is too large
Load diff
|
@ -1,16 +0,0 @@
|
|||
|
||||
# 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)
|
101
02/puzzle.input
101
02/puzzle.input
|
@ -1,101 +0,0 @@
|
|||
Game 1: 19 blue, 12 red; 19 blue, 2 green, 1 red; 13 red, 11 blue
|
||||
Game 2: 1 green, 1 blue, 1 red; 11 red, 3 blue; 1 blue, 18 red; 9 red, 1 green; 2 blue, 11 red, 1 green; 1 green, 2 blue, 10 red
|
||||
Game 3: 3 blue, 2 red, 6 green; 4 blue, 6 green, 1 red; 11 green, 12 blue; 2 red, 6 green, 4 blue; 4 green
|
||||
Game 4: 10 red, 5 green, 5 blue; 3 red, 3 blue, 6 green; 2 blue, 9 red, 6 green; 8 green, 10 red, 4 blue; 9 red, 2 green, 3 blue; 1 blue, 5 red, 15 green
|
||||
Game 5: 11 green, 7 blue; 5 green, 5 red, 1 blue; 1 green, 1 red, 4 blue; 1 red, 1 blue, 4 green; 4 blue, 1 red, 10 green; 5 red, 6 green
|
||||
Game 6: 1 green, 1 red, 11 blue; 1 blue, 2 green; 1 red, 5 green, 9 blue; 7 blue; 1 red, 2 green, 9 blue; 12 blue, 1 red, 2 green
|
||||
Game 7: 1 blue, 10 red, 7 green; 14 blue, 10 green; 12 red, 2 green; 16 red, 13 blue, 1 green; 12 green, 10 red, 3 blue; 9 red, 19 blue, 11 green
|
||||
Game 8: 3 blue, 1 green, 3 red; 4 blue, 10 red, 6 green; 1 green, 10 red, 9 blue; 9 blue, 7 red, 8 green; 8 green, 12 red, 8 blue; 6 blue, 1 green, 13 red
|
||||
Game 9: 10 green, 2 blue, 11 red; 2 green, 2 red; 6 blue, 8 red, 13 green
|
||||
Game 10: 8 red, 3 blue, 5 green; 5 green, 7 blue, 1 red; 3 red, 10 blue, 6 green; 2 red, 6 green, 7 blue; 3 blue, 11 red, 4 green; 8 red, 8 blue, 4 green
|
||||
Game 11: 14 green, 9 red; 3 blue, 6 green, 8 red; 14 green
|
||||
Game 12: 10 red, 5 blue, 1 green; 4 blue, 8 red; 5 blue, 1 green, 6 red; 14 red, 4 blue; 1 green, 11 red, 3 blue
|
||||
Game 13: 1 blue, 16 green, 1 red; 6 red, 2 blue, 5 green; 2 blue, 12 red, 10 green; 3 red, 4 blue, 13 green; 14 red, 4 blue, 12 green; 7 red, 2 green
|
||||
Game 14: 17 red, 11 blue, 3 green; 16 red, 3 blue, 8 green; 3 green, 9 red, 13 blue; 4 green, 15 red, 14 blue
|
||||
Game 15: 7 blue, 2 red, 2 green; 1 green, 5 red, 6 blue; 3 green, 6 red, 2 blue
|
||||
Game 16: 3 red, 3 green; 6 green, 4 red, 3 blue; 3 red, 4 blue; 4 blue, 2 red, 4 green
|
||||
Game 17: 6 red, 1 blue, 5 green; 3 red, 1 green, 12 blue; 13 green, 1 blue; 5 blue, 7 green, 6 red; 5 blue, 14 green, 2 red; 4 green, 6 red, 10 blue
|
||||
Game 18: 4 red, 8 blue; 8 blue, 4 red; 12 blue, 1 green
|
||||
Game 19: 1 blue, 15 green, 9 red; 1 red, 3 green; 4 blue, 2 green, 1 red
|
||||
Game 20: 7 blue, 4 green, 12 red; 1 red, 9 green, 8 blue; 4 blue, 2 green; 13 green, 8 blue; 3 red, 4 green, 1 blue; 6 green, 7 red, 3 blue
|
||||
Game 21: 9 green, 4 blue, 8 red; 5 blue; 7 red, 8 blue, 1 green
|
||||
Game 22: 3 green, 4 red; 6 red, 3 green; 4 red, 1 blue, 1 green; 11 red, 3 green, 1 blue; 7 red, 1 blue
|
||||
Game 23: 3 blue, 4 green; 3 green, 1 red; 1 red, 2 blue, 4 green
|
||||
Game 24: 2 blue, 3 green; 9 red, 4 green; 2 blue, 9 red; 2 green, 10 red, 1 blue; 1 blue, 1 red, 5 green
|
||||
Game 25: 8 green, 4 blue; 9 blue, 7 red; 5 green, 15 blue, 11 red; 11 green, 14 red, 10 blue
|
||||
Game 26: 3 blue; 2 red, 1 green; 2 red, 3 blue; 10 blue, 1 red, 3 green; 1 green, 2 red; 1 green, 6 blue
|
||||
Game 27: 1 green, 6 blue; 2 green, 1 red, 6 blue; 1 red, 2 blue, 1 green
|
||||
Game 28: 8 blue, 1 red, 5 green; 1 red; 3 green, 4 red, 2 blue; 4 green, 2 red, 4 blue; 5 blue, 3 red, 7 green
|
||||
Game 29: 2 green, 4 blue; 7 blue, 4 red, 10 green; 7 blue, 9 green; 14 green, 7 red, 5 blue
|
||||
Game 30: 19 green, 3 red; 19 green; 1 blue, 14 green; 2 blue, 5 green; 3 red, 19 green
|
||||
Game 31: 3 red, 1 green, 4 blue; 10 blue; 3 red, 4 green, 5 blue; 10 blue, 1 red, 6 green
|
||||
Game 32: 19 red, 1 green, 2 blue; 1 blue, 6 green, 13 red; 10 green, 9 red; 11 red, 2 blue, 6 green; 8 green, 5 red
|
||||
Game 33: 2 red, 8 blue, 2 green; 1 red, 3 green; 9 red, 9 blue, 1 green; 6 red, 1 green; 9 blue, 1 green, 8 red; 5 green, 10 red, 8 blue
|
||||
Game 34: 1 red, 6 blue, 2 green; 7 red; 14 red, 13 blue; 13 red, 12 blue; 1 green, 9 red, 13 blue; 2 green, 15 blue
|
||||
Game 35: 8 blue, 2 red, 3 green; 2 green, 2 red; 3 red, 6 blue, 2 green; 2 green, 6 blue; 1 green, 5 blue, 4 red; 3 green, 6 blue
|
||||
Game 36: 3 red, 5 blue, 10 green; 1 red, 1 green, 7 blue; 2 blue, 2 green, 1 red
|
||||
Game 37: 8 red, 7 green; 5 green, 1 blue, 6 red; 7 red, 6 blue, 11 green
|
||||
Game 38: 4 green, 10 red, 9 blue; 12 green, 2 blue, 2 red; 6 red, 6 blue, 9 green; 1 blue, 1 green, 6 red; 3 blue, 1 red, 5 green; 5 blue, 2 red, 12 green
|
||||
Game 39: 1 blue, 2 red; 7 blue, 2 green, 1 red; 7 blue, 11 green, 3 red; 8 blue, 13 green, 1 red; 6 green, 6 blue, 3 red
|
||||
Game 40: 8 green, 5 blue; 5 green, 1 blue, 10 red; 9 green, 3 blue; 3 green, 7 red; 2 green, 3 blue, 5 red
|
||||
Game 41: 7 green, 8 red; 3 blue, 15 green, 7 red; 2 red, 2 green, 4 blue; 10 green, 4 red, 5 blue; 3 red, 8 blue, 9 green; 7 red, 8 green
|
||||
Game 42: 6 blue, 12 green; 3 red, 1 green; 1 red, 12 green, 3 blue; 10 red, 9 green; 9 red, 4 green, 5 blue
|
||||
Game 43: 11 red, 6 green; 2 blue, 11 red; 3 red, 1 blue; 3 green, 11 red, 2 blue; 4 red, 5 green, 1 blue; 8 green, 2 blue, 17 red
|
||||
Game 44: 2 green, 9 blue, 3 red; 7 blue, 1 green, 4 red; 1 green
|
||||
Game 45: 1 green, 10 red; 5 red, 10 green, 1 blue; 11 red, 3 green, 2 blue; 2 blue, 3 green, 4 red; 7 green, 3 red, 2 blue; 1 blue, 10 red
|
||||
Game 46: 1 green, 4 blue, 7 red; 13 blue, 2 green, 9 red; 7 blue, 3 red, 1 green
|
||||
Game 47: 4 blue; 2 green, 2 red, 1 blue; 1 green, 1 red, 4 blue; 1 green, 2 red, 2 blue; 2 blue, 2 red
|
||||
Game 48: 5 green, 10 red; 7 red, 5 green; 1 green, 11 red; 12 red, 11 green; 11 red, 1 blue, 1 green
|
||||
Game 49: 2 green, 1 red, 1 blue; 1 blue, 2 red; 2 green, 1 red, 2 blue; 1 blue, 1 red, 1 green
|
||||
Game 50: 5 green, 2 blue; 4 green, 4 blue, 3 red; 1 red, 7 green, 3 blue
|
||||
Game 51: 9 green, 1 red, 2 blue; 7 red, 3 blue, 6 green; 5 green, 4 blue, 5 red
|
||||
Game 52: 2 green, 4 blue, 1 red; 2 blue, 2 red, 13 green; 8 blue, 3 green; 3 green, 4 blue, 2 red; 2 green
|
||||
Game 53: 3 red; 4 blue, 4 red; 2 blue, 2 red; 6 blue, 1 red, 2 green; 1 red, 1 green, 6 blue; 2 blue, 4 red
|
||||
Game 54: 3 blue, 3 green, 18 red; 4 blue, 18 red, 3 green; 7 blue, 4 green
|
||||
Game 55: 1 green, 2 red, 3 blue; 1 red, 4 blue, 1 green; 3 blue, 2 red; 2 blue, 1 green; 3 blue, 2 red; 1 blue, 1 green, 1 red
|
||||
Game 56: 12 green, 2 red, 1 blue; 11 green, 16 red, 13 blue; 7 red, 5 blue, 12 green; 4 blue, 16 red; 5 red, 1 blue, 3 green
|
||||
Game 57: 5 green, 17 blue, 11 red; 6 blue, 1 green; 1 green, 5 blue, 8 red; 9 green, 11 red, 1 blue; 9 green, 11 blue, 7 red; 8 green, 4 blue
|
||||
Game 58: 5 red, 10 blue, 6 green; 5 green, 11 blue, 5 red; 9 green; 4 red, 2 green
|
||||
Game 59: 2 red, 6 blue, 1 green; 1 green, 12 blue; 2 red
|
||||
Game 60: 6 blue, 10 green, 9 red; 8 red, 19 blue, 2 green; 16 red, 10 green, 12 blue; 13 red, 12 blue, 6 green
|
||||
Game 61: 12 green, 1 red, 3 blue; 3 red, 4 blue, 19 green; 1 blue, 7 green
|
||||
Game 62: 7 red, 6 blue, 8 green; 10 blue, 3 green, 17 red; 13 blue, 3 red, 10 green; 13 red, 5 blue, 9 green; 12 blue, 4 red; 10 red, 4 green
|
||||
Game 63: 19 green, 4 red; 5 blue, 4 red, 1 green; 4 red, 2 blue, 15 green; 5 green, 4 red, 5 blue
|
||||
Game 64: 6 red, 3 green; 6 green, 3 red, 3 blue; 3 blue, 8 red, 5 green; 3 blue, 7 red, 1 green; 1 blue, 6 red, 6 green
|
||||
Game 65: 1 green, 9 blue; 6 blue, 4 green, 6 red; 6 blue, 5 green; 3 red, 1 blue, 4 green
|
||||
Game 66: 1 blue, 2 red; 2 green, 1 blue; 2 red, 1 blue, 1 green; 1 blue, 1 green
|
||||
Game 67: 16 blue, 1 green; 1 blue, 2 green, 2 red; 1 red, 9 blue; 12 blue, 4 green, 1 red; 6 green, 11 blue, 3 red
|
||||
Game 68: 6 blue, 2 red, 1 green; 2 blue, 2 green; 1 green, 7 red, 15 blue; 14 blue, 12 green, 3 red; 13 green, 10 red, 6 blue; 2 green, 5 blue, 1 red
|
||||
Game 69: 2 red, 1 blue, 2 green; 1 blue, 7 green, 1 red; 3 blue, 1 red, 7 green; 2 red, 1 blue, 11 green
|
||||
Game 70: 2 green, 9 red, 3 blue; 12 blue, 1 green, 13 red; 6 red, 1 green, 5 blue; 1 red, 17 blue
|
||||
Game 71: 7 red, 5 green, 6 blue; 5 blue, 5 green; 7 green, 4 blue; 2 green, 4 blue, 8 red; 10 red, 8 green; 3 blue, 13 red, 7 green
|
||||
Game 72: 13 red, 17 green; 9 red, 20 green, 3 blue; 1 green, 3 blue, 8 red
|
||||
Game 73: 1 blue, 7 red, 2 green; 2 green, 1 blue, 8 red; 1 blue, 2 red; 4 red, 7 green; 4 red, 5 green; 3 green, 7 red
|
||||
Game 74: 2 green, 14 blue; 1 red, 1 blue, 7 green; 1 red, 8 green, 11 blue; 4 green, 12 blue; 1 green, 5 blue
|
||||
Game 75: 12 blue, 1 red; 1 red, 7 blue, 4 green; 4 blue, 6 green; 4 green, 3 blue, 1 red
|
||||
Game 76: 7 green, 5 red, 6 blue; 18 red, 1 green; 14 green, 4 red, 15 blue; 4 blue, 6 red
|
||||
Game 77: 2 blue, 2 green, 2 red; 2 blue, 1 red, 1 green; 2 green, 1 red; 6 blue, 4 green; 1 red, 1 blue, 6 green
|
||||
Game 78: 5 red, 16 blue, 12 green; 11 blue, 3 red, 2 green; 13 blue, 4 red
|
||||
Game 79: 9 red, 11 green, 6 blue; 1 red, 3 green; 7 blue, 7 red, 11 green; 8 red, 9 blue, 11 green; 7 red, 11 green, 4 blue
|
||||
Game 80: 7 green, 5 red, 2 blue; 1 blue, 7 green, 1 red; 2 red, 2 blue; 1 red, 4 blue, 12 green; 4 green, 2 blue
|
||||
Game 81: 5 blue, 2 green, 12 red; 2 green, 1 blue, 5 red; 3 blue, 13 red, 3 green; 3 green, 9 blue, 3 red; 10 blue, 4 red, 3 green
|
||||
Game 82: 11 blue, 1 red, 9 green; 11 green, 1 blue, 12 red; 13 red, 6 blue, 19 green
|
||||
Game 83: 6 red, 5 blue, 16 green; 4 green, 17 blue, 9 red; 15 red, 2 green, 9 blue
|
||||
Game 84: 19 green, 11 blue, 3 red; 1 blue, 18 green, 6 red; 17 blue, 5 green, 4 red; 18 blue, 7 green, 3 red
|
||||
Game 85: 3 green, 15 blue; 12 blue; 2 green, 1 red; 1 red, 9 blue, 1 green; 12 blue, 3 red, 1 green
|
||||
Game 86: 3 green, 4 blue, 5 red; 9 red, 4 green, 1 blue; 6 green, 1 blue, 8 red; 3 green, 2 blue, 5 red
|
||||
Game 87: 2 red, 8 blue, 5 green; 3 red, 5 blue, 10 green; 2 red, 3 green
|
||||
Game 88: 16 green, 13 red; 7 green, 1 blue, 2 red; 7 red, 12 green; 5 red, 7 green, 2 blue; 2 blue, 10 green, 7 red; 8 red, 16 green
|
||||
Game 89: 1 blue, 8 red; 2 green, 10 red, 12 blue; 13 green, 14 blue; 10 blue, 15 red, 13 green; 2 green, 5 red, 13 blue
|
||||
Game 90: 16 blue, 7 red, 4 green; 4 green, 6 red, 11 blue; 2 red, 8 blue, 2 green; 5 green, 8 red, 10 blue; 4 red, 2 green, 7 blue; 4 green, 5 blue, 5 red
|
||||
Game 91: 4 red, 4 green, 1 blue; 3 blue, 2 green; 6 blue, 4 green, 5 red; 2 red, 6 blue, 4 green; 6 blue, 1 green
|
||||
Game 92: 1 red, 3 green; 3 blue, 6 green; 5 blue, 1 red, 11 green; 1 red; 3 green, 13 blue
|
||||
Game 93: 1 red, 14 blue, 6 green; 10 blue, 6 red; 9 green, 15 red, 17 blue; 9 red, 1 green, 9 blue
|
||||
Game 94: 3 red, 14 green; 3 blue, 15 green, 3 red; 2 red, 15 green
|
||||
Game 95: 4 blue, 13 red; 5 blue, 1 green, 11 red; 3 green, 3 blue, 10 red; 13 red, 6 blue; 2 green, 5 blue; 3 green, 11 red
|
||||
Game 96: 7 blue, 1 green; 1 green, 4 blue; 1 green, 2 red, 5 blue; 1 red, 2 blue, 1 green; 1 blue
|
||||
Game 97: 15 green, 9 blue; 14 blue, 14 red, 2 green; 18 red, 12 blue, 2 green
|
||||
Game 98: 1 green, 9 red; 1 red, 2 green, 7 blue; 8 red, 1 blue; 6 red, 2 green; 1 green, 6 blue
|
||||
Game 99: 1 green, 2 red, 6 blue; 6 red, 1 green, 5 blue; 11 blue, 6 red; 11 red, 1 green; 1 green, 11 red, 9 blue
|
||||
Game 100: 12 green, 8 blue, 2 red; 7 blue, 14 red, 8 green; 14 red, 1 blue, 4 green
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
|
||||
# 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)
|
137
02/src/main.c
137
02/src/main.c
|
@ -1,137 +0,0 @@
|
|||
/**
|
||||
* Copyright [2023] Jiří Štefka <jiriks74>
|
||||
* Project: AdventOfCode
|
||||
* @file main.c
|
||||
* @brief Main entry point
|
||||
* @author jiriks74
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
const int MAX_RED = 12;
|
||||
const int MAX_GREEN = 13;
|
||||
const int MAX_BLUE = 14;
|
||||
|
||||
typedef struct {
|
||||
int red;
|
||||
int green;
|
||||
int blue;
|
||||
} GameShow;
|
||||
|
||||
/**
|
||||
* @brief Count how many cubes of each color were in a show
|
||||
* @param *show A show of cubes in a game
|
||||
* @return A count of all the cubes in a struct
|
||||
*/
|
||||
GameShow get_max_cube_counts(char *game) {
|
||||
char *curr = game;
|
||||
GameShow result = {0};
|
||||
|
||||
while (curr != NULL) {
|
||||
char *end_show = strchr(curr, ';');
|
||||
|
||||
if (end_show != NULL) {
|
||||
*end_show = '\0';
|
||||
}
|
||||
|
||||
while (curr != NULL) {
|
||||
int cube_count = atoi(curr);
|
||||
|
||||
curr = strchr(curr, ' ');
|
||||
curr += sizeof(char);
|
||||
|
||||
if (*curr == 'r') {
|
||||
if (cube_count > result.red)
|
||||
result.red = cube_count;
|
||||
} else if (*curr == 'g') {
|
||||
if (cube_count > result.green)
|
||||
result.green = cube_count;
|
||||
} else if (*curr == 'b') {
|
||||
if (cube_count > result.blue)
|
||||
result.blue = cube_count;
|
||||
} else {
|
||||
result.red = -1;
|
||||
result.green = -1;
|
||||
result.blue = -1;
|
||||
return result;
|
||||
}
|
||||
curr = strchr(curr, ',');
|
||||
if (curr != NULL)
|
||||
curr += sizeof(char) * 2;
|
||||
}
|
||||
|
||||
if (end_show != NULL) {
|
||||
*end_show = ';';
|
||||
curr = end_show + sizeof(char) * 2;
|
||||
} else
|
||||
curr = end_show;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Count how many times were the cubes shown
|
||||
* @return Number of shows or -1 when error occurs
|
||||
*/
|
||||
bool is_game_possible(char *game) {
|
||||
// char *curr = strchr(game, ':');
|
||||
// curr += sizeof(char) * 2;
|
||||
|
||||
// if (curr == NULL) {
|
||||
// return false;
|
||||
// }
|
||||
|
||||
GameShow show_counts = get_max_cube_counts(game);
|
||||
|
||||
if (show_counts.red > MAX_RED)
|
||||
return false;
|
||||
else if (show_counts.green > MAX_GREEN)
|
||||
return false;
|
||||
else if (show_counts.blue > MAX_BLUE)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifndef TESTING
|
||||
/**
|
||||
* @brief Main entry point
|
||||
* @param argc Number of command-line arguments.
|
||||
* @param argv Array of command-line arguments.
|
||||
*/
|
||||
int main(int argc, char *argv[])
|
||||
#endif
|
||||
#ifdef TESTING
|
||||
int main_test(int argc, char *argv[])
|
||||
#endif
|
||||
{
|
||||
FILE *input = fopen(argv[1], "r");
|
||||
|
||||
int possible_game_ids_sum = 0;
|
||||
int sum_of_powers = 0;
|
||||
|
||||
char line[512];
|
||||
while (fgets(line, sizeof(line), input)) {
|
||||
if (*line != 'G')
|
||||
break;
|
||||
|
||||
int curr_game_id = atoi(line + sizeof("Game"));
|
||||
|
||||
// if (is_game_possible(line)) {
|
||||
if (is_game_possible(strchr(line, ':') + sizeof(char) * 2)) {
|
||||
possible_game_ids_sum += curr_game_id;
|
||||
// printf("Game %d is possible\n", curr_game_id);
|
||||
} // else
|
||||
// printf("Game %d is impossible\n", curr_game_id);
|
||||
GameShow min_cubes =
|
||||
get_max_cube_counts(strchr(line, ':') + sizeof(char) * 2);
|
||||
sum_of_powers += min_cubes.red * min_cubes.green * min_cubes.blue;
|
||||
}
|
||||
|
||||
printf("Sum of possible game IDs: %d\n", possible_game_ids_sum);
|
||||
printf("Sum of powers: %d\n", sum_of_powers);
|
||||
return 0;
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green
|
||||
Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue
|
||||
Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red
|
||||
Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red
|
||||
Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green
|
|
@ -1,83 +0,0 @@
|
|||
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()
|
|
@ -1,17 +0,0 @@
|
|||
|
||||
# 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)
|
|
@ -1,31 +0,0 @@
|
|||
#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…
Reference in a new issue