c 2024 part 2 got it in one hell yeah
This commit is contained in:
parent
413d4d4631
commit
8e5f922f63
@ -87,6 +87,30 @@ int target_string_count(Puzzle *puzzle, int index) {
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char mas[4];
|
||||||
|
int xmas_count(Puzzle *puzzle, int index) {
|
||||||
|
if (puzzle->text[index] != 'A') return 0;
|
||||||
|
int count = 0;
|
||||||
|
int row = index / puzzle->width;
|
||||||
|
int column = index % puzzle->width;
|
||||||
|
if (
|
||||||
|
puzzle_inbounds(puzzle, row - 1, column + 1) &&
|
||||||
|
puzzle_inbounds(puzzle, row + 1, column + 1) &&
|
||||||
|
puzzle_inbounds(puzzle, row + 1, column - 1) &&
|
||||||
|
puzzle_inbounds(puzzle, row - 1, column - 1)
|
||||||
|
) {
|
||||||
|
mas[0] = puzzle_char_at(puzzle, row - 1, column + 1);
|
||||||
|
mas[1] = puzzle_char_at(puzzle, row + 1, column + 1);
|
||||||
|
mas[2] = puzzle_char_at(puzzle, row + 1, column - 1);
|
||||||
|
mas[3] = puzzle_char_at(puzzle, row - 1, column - 1);
|
||||||
|
if (((mas[0] == 'M' && mas[2] == 'S') || (mas[0] == 'S' && mas[2] == 'M')) &&
|
||||||
|
((mas[1] == 'M' && mas[3] == 'S') || (mas[1] == 'S' && mas[3] == 'M'))) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
char *input = aoc_read_input();
|
char *input = aoc_read_input();
|
||||||
int width = strchr(input, '\n') - input + 1;
|
int width = strchr(input, '\n') - input + 1;
|
||||||
@ -98,13 +122,15 @@ int main() {
|
|||||||
p.height = height;
|
p.height = height;
|
||||||
|
|
||||||
int sum = 0;
|
int sum = 0;
|
||||||
|
int xmas_sum = 0;
|
||||||
|
|
||||||
for (int i = 0; i < strlen(input); i++) {
|
for (int i = 0; i < strlen(input); i++) {
|
||||||
sum += target_string_count(&p, i);
|
sum += target_string_count(&p, i);
|
||||||
|
xmas_sum += xmas_count(&p, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Part 1: %d\n", sum);
|
printf("Part 1: %d\n", sum);
|
||||||
// printf("Part 2: %d\n", cond_sum);
|
printf("Part 2: %d\n", xmas_sum);
|
||||||
|
|
||||||
aoc_free();
|
aoc_free();
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user