diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..c2098a2 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,18 @@ +{ + "configurations": [ + { + "name": "linux-gcc-x64", + "includePath": [ + "${workspaceFolder}/**" + ], + "compilerPath": "/usr/bin/gcc", + "cStandard": "${default}", + "cppStandard": "${default}", + "intelliSenseMode": "linux-gcc-x64", + "compilerArgs": [ + "" + ] + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json index 62d888b..e589313 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,15 +1,31 @@ { - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ + "version": "0.2.0", + "configurations": [ + { + "name": "Python: Debug Console", + "type": "python", + "request": "launch", + "program": "${file}", + "console": "internalConsole" + }, + { + "name": "C/C++ Runner: Debug Session", + "type": "cppdbg", + "request": "launch", + "args": [], + "stopAtEntry": false, + "externalConsole": false, + "cwd": "/home/icaema/Public/advent-of-code/day-02/src", + "program": "/home/icaema/Public/advent-of-code/day-02/src/build/Debug/outDebug", + "MIMode": "gdb", + "miDebuggerPath": "gdb", + "setupCommands": [ { - "name": "Python: Debug Console", - "type": "python", - "request": "launch", - "program": "${file}", - "console": "internalConsole" - } - ] + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + } + ] } \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..1eb85dd --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,68 @@ +{ + "C_Cpp_Runner.cCompilerPath": "gcc", + "C_Cpp_Runner.cppCompilerPath": "g++", + "C_Cpp_Runner.debuggerPath": "gdb", + "C_Cpp_Runner.cStandard": "", + "C_Cpp_Runner.cppStandard": "", + "C_Cpp_Runner.msvcBatchPath": "", + "C_Cpp_Runner.useMsvc": false, + "C_Cpp_Runner.warnings": [ + "-Wall", + "-Wextra", + "-Wpedantic", + "-Wshadow", + "-Wformat=2", + "-Wcast-align", + "-Wconversion", + "-Wsign-conversion", + "-Wnull-dereference" + ], + "C_Cpp_Runner.msvcWarnings": [ + "/W4", + "/permissive-", + "/w14242", + "/w14287", + "/w14296", + "/w14311", + "/w14826", + "/w44062", + "/w44242", + "/w14905", + "/w14906", + "/w14263", + "/w44265", + "/w14928" + ], + "C_Cpp_Runner.enableWarnings": true, + "C_Cpp_Runner.warningsAsError": false, + "C_Cpp_Runner.compilerArgs": [], + "C_Cpp_Runner.linkerArgs": [], + "C_Cpp_Runner.includePaths": [], + "C_Cpp_Runner.includeSearch": [ + "*", + "**/*" + ], + "C_Cpp_Runner.excludeSearch": [ + "**/build", + "**/build/**", + "**/.*", + "**/.*/**", + "**/.vscode", + "**/.vscode/**" + ], + "C_Cpp_Runner.useAddressSanitizer": false, + "C_Cpp_Runner.useUndefinedSanitizer": false, + "C_Cpp_Runner.useLeakSanitizer": false, + "C_Cpp_Runner.showCompilationTime": false, + "C_Cpp_Runner.useLinkTimeOptimization": false, + "C_Cpp_Runner.msvcSecureNoWarnings": false, + "makefile.makefilePath": "day-02/Makefile", + "makefile.makeDirectory": "day-02", + "makefile.launchConfigurations": [ + { + "cwd": "/home/icaema/Public/advent-of-code/day-02/bin", + "binaryPath": "/home/icaema/Public/advent-of-code/day-02/bin/part01", + "binaryArgs": [] + } + ] +} \ No newline at end of file diff --git a/day-02/Makefile b/day-02/Makefile index c692cd7..099be55 100644 --- a/day-02/Makefile +++ b/day-02/Makefile @@ -1,16 +1,16 @@ CC=gcc CFLAGS=-Wall -run1: bin/part01 +run1: clean bin/part01 cat data/p01data.txt | bin/part01 -run2: bin/part02 +run2: clean bin/part02 cat data/p02data.txt | bin/part02 -test1: bin/part01 +test1: clean bin/part01 cat data/p01test.txt | bin/part01 -test2: bin/part02 +test2: clean bin/part02 cat data/p02test.txt | bin/part02 bin/part01: diff --git a/day-02/bin/part01 b/day-02/bin/part01 new file mode 100755 index 0000000..65faca6 Binary files /dev/null and b/day-02/bin/part01 differ diff --git a/day-02/src/build/Debug/outDebug b/day-02/src/build/Debug/outDebug new file mode 100755 index 0000000..7552ea3 Binary files /dev/null and b/day-02/src/build/Debug/outDebug differ diff --git a/day-02/src/build/Debug/part01.o b/day-02/src/build/Debug/part01.o new file mode 100644 index 0000000..7580281 Binary files /dev/null and b/day-02/src/build/Debug/part01.o differ diff --git a/day-02/src/part01.c b/day-02/src/part01.c index 588b32c..9c01b82 100644 --- a/day-02/src/part01.c +++ b/day-02/src/part01.c @@ -1,25 +1,144 @@ +#include +#include #include #include #include +#define DEBUG + #ifdef DEBUG #define debug_printf(...) do{ fprintf( stderr, __VA_ARGS__ ); } while( 0 ) #else #define debug_printf(...) do{ } while ( 0 ) #endif -#define LINE_MAX 90 +#define LINE_MAX 160 +#define GAME_MAX 101 +#define GAME_MAX_HANDS 10 + + + +typedef struct Hand { + int red; + int green; + int blue; + int set; +} Hand; + + +typedef struct Game { + int id; + int num_hands; + Hand hands[GAME_MAX_HANDS]; + Hand min_cubes; + int valid; +} Game; + +Game gameArray[GAME_MAX]; + +Hand bag_limits = {12, 13, 14, 1}; + +//Takes a game as a param, returns if the game is valid 0 or 1 +int validateGame(Game game, Hand limit){ + if (game.id == 0) return 0; + if (game.num_hands == 0) return 0; + for (int i=0; i limit.red) return 0; + if (game.hands[i].green > limit.green) return 0; + if (game.hands[i].blue > limit.blue) return 0; + } + return 1; +} + +void genHandString(char* dest, Game game){ + int offset = 0; + for (int i=0; i