This commit is contained in:
benjamyn committed 2023-12-25 11:39:35 +12:00
1 parent 1ef0d29c9f
commit 4819b63b8d
17 files changed
+329 -29

No files matched your search

+1 -1
View File
@@ -1 +1 @@
/home/ben/Documents/Projects/C/advent-of-code/libs
../libs
+22 -19
View File
@@ -4,22 +4,25 @@
#include "libs/fileLoader.h"
#include "libs/strTools.h"
#define testing
#define MAX_STR_LEN 255
#ifdef testing
#define LineCount 7
#define OUR_LEN 5
#define WIN_LEN 8
#else
// defaults
// #define LineCount 219
// #define OUR_LEN 10
// #define WIN_LEN 25
#define LineCount 219
#define OUR_LEN 10
#define WIN_LEN 25
#endif
struct ScratchCards
{
int cards[LineCount];
};
struct Game
typedef struct Game
{
int ourNumbers[OUR_LEN];
int ourIterator;
@@ -28,17 +31,17 @@ struct Game
int gamesWon;
int game_id;
};
} Game;
struct Games
typedef struct Games
{
struct Game games[LineCount];
Game games[LineCount];
int iterator;
};
} Games;
struct Game *lineParser(char *line) // , struct Games *games
Game *lineParser(char *line) // , Games *games
{
struct Game *game = malloc(sizeof(struct Game));
Game *game = malloc(sizeof(Game));
game->ourIterator = 0;
game->winIterator = 0;
game->gamesWon = 0;
@@ -127,7 +130,7 @@ int main()
int total = 0;
// Load the input file into my structs
struct Games *games = malloc(sizeof(struct Games));
Games *games = malloc(sizeof(Games));
games->iterator = 0;
// char *line = (char *)malloc(MAX_STR_LEN); // Start new line variable?
@@ -158,7 +161,7 @@ int main()
cards->cards[i] = 1;
}
for (int gameId = 0; gameId <= LineCount; gameId++)
for (int gameId = 0; gameId < LineCount - 1; gameId++)
{
if (gameId == games->iterator)
{
@@ -166,12 +169,12 @@ int main()
}
// cards->cards[gameId] += 1; Uneeded as we default them to 1 games won
int winningGames = games->games[gameId].gamesWon;
int iterations = winningGames + cards->cards[gameId];
for (int i = 1; i <= iterations; i++)
int iterations = winningGames * cards->cards[gameId];
for (int i = 0; i <= iterations; i++)
{
if (cards->cards[gameId + i] < LineCount - 1)
if (gameId + (i + 1) <= LineCount)
{
cards->cards[gameId + i]++;
cards->cards[gameId + (i + 1)]++;
}
}
// int winningGames = games->games[gameId].gamesWon;
@@ -182,7 +185,7 @@ int main()
}
// Finish sad loop and cry
for (int i = 0; i < LineCount; i++)
for (int i = 0; i <= LineCount; i++)
{
total += cards->cards[i];
}