Bring ISDIGIT macro in part 1 of the day 3 as well.
This commit is contained in:
parent
2c30c9e195
commit
2d3e387f4f
23
day3/p1.c
23
day3/p1.c
@ -4,7 +4,8 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <ctype.h>
|
|
||||||
|
#define ISDIGIT(c) (c >= 0x30 && c <= 0x39)
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
FILE *input;
|
FILE *input;
|
||||||
@ -44,22 +45,22 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
for (ssize_t i = engine_lines-1; i >= 0; --i) {
|
for (ssize_t i = engine_lines-1; i >= 0; --i) {
|
||||||
for (ssize_t j = engine_line_size-1; j >= 0; --j) {
|
for (ssize_t j = engine_line_size-1; j >= 0; --j) {
|
||||||
if (isdigit(engine[i][j])) {
|
if (ISDIGIT(engine[i][j])) {
|
||||||
n += (engine[i][j]&0xf) * multiplier;
|
n += (engine[i][j]&0xf) * multiplier;
|
||||||
multiplier *= 10;
|
multiplier *= 10;
|
||||||
|
|
||||||
if (adjacent == false && ((j+1 <= engine_line_size-1 && !isdigit(engine[i][j+1]) && engine[i][j+1] != '.') ||
|
if (adjacent == false && ((j+1 <= engine_line_size-1 && !ISDIGIT(engine[i][j+1]) && engine[i][j+1] != '.') ||
|
||||||
(j-1 >=0 && !isdigit(engine[i][j-1]) && engine[i][j-1] != '.') ||
|
(j-1 >=0 && !ISDIGIT(engine[i][j-1]) && engine[i][j-1] != '.') ||
|
||||||
(i+1 <= engine_lines-1 && !isdigit(engine[i+1][j]) && engine[i+1][j] != '.') ||
|
(i+1 <= engine_lines-1 && !ISDIGIT(engine[i+1][j]) && engine[i+1][j] != '.') ||
|
||||||
(i-1 >= 0 && !isdigit(engine[i-1][j]) && engine[i-1][j] != '.') ||
|
(i-1 >= 0 && !ISDIGIT(engine[i-1][j]) && engine[i-1][j] != '.') ||
|
||||||
((i+1 <= engine_lines-1 && j+1 <= engine_line_size-1) && !isdigit(engine[i+1][j+1]) && engine[i+1][j+1] != '.') ||
|
((i+1 <= engine_lines-1 && j+1 <= engine_line_size-1) && !ISDIGIT(engine[i+1][j+1]) && engine[i+1][j+1] != '.') ||
|
||||||
((i+1 <= engine_lines-1 && j-1 >= 0) && !isdigit(engine[i+1][j-1]) && engine[i+1][j-1] != '.') ||
|
((i+1 <= engine_lines-1 && j-1 >= 0) && !ISDIGIT(engine[i+1][j-1]) && engine[i+1][j-1] != '.') ||
|
||||||
((i-1 >= 0 && j+1 <= engine_line_size-1) && !isdigit(engine[i-1][j+1]) && engine[i-1][j+1] != '.') ||
|
((i-1 >= 0 && j+1 <= engine_line_size-1) && !ISDIGIT(engine[i-1][j+1]) && engine[i-1][j+1] != '.') ||
|
||||||
((i-1 >= 0 && j-1 >= 0) && !isdigit(engine[i-1][j-1]) && engine[i-1][j-1] != '.'))) {
|
((i-1 >= 0 && j-1 >= 0) && !ISDIGIT(engine[i-1][j-1]) && engine[i-1][j-1] != '.'))) {
|
||||||
adjacent = true;
|
adjacent = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((!isdigit(engine[i][j]) || j == 0) && n != 0) {
|
if ((!ISDIGIT(engine[i][j]) || j == 0) && n != 0) {
|
||||||
if (adjacent)
|
if (adjacent)
|
||||||
part_number += n;
|
part_number += n;
|
||||||
n = 0;
|
n = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user