From 9128415dd08c17dc84d3c0cf37b84eb350ad5312 Mon Sep 17 00:00:00 2001 From: icaema Date: Sat, 2 Dec 2023 15:16:49 -0500 Subject: [PATCH] d02p02 implemented in c --- day-02/src/part02.c | 147 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 143 insertions(+), 4 deletions(-) diff --git a/day-02/src/part02.c b/day-02/src/part02.c index 588b32c..0bd349a 100644 --- a/day-02/src/part02.c +++ b/day-02/src/part02.c @@ -1,25 +1,164 @@ +#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; +} + +//Takes a game as a param, returns hand of min size for inputs +Hand minCubes(Game game){ + Hand min = (Hand){0,0,0,0}; + if (game.id == 0) return min; + if (game.num_hands == 0) return min; + for (int i=0; i min.red) min.red = game.hands[i].red; + if (game.hands[i].green > min.green) min.green = game.hands[i].green; + if (game.hands[i].blue > min.blue) min.blue = game.hands[i].blue; + } + min.set = 1; + return min; +} + +void genHandString(char* dest, Game game){ + int offset = 0; + for (int i=0; i