Overview
| Comment: | 202403 1st star |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | trunk |
| Files: | files | file ages | folders |
| SHA3-256: |
90b164fce23b11ae6151268b3e20b08d |
| User & Date: | nnz on 2024-12-03 10:00:48.115 |
| Original Comment: | day 3, part 1 solved |
| Other Links: | manifest | tags |
Context
|
2024-12-03
| ||
| 10:36 | 202403 2nd star check-in: e8b841e9cf user: nnz tags: trunk | |
| 10:00 | 202403 1st star check-in: 90b164fce2 user: nnz tags: trunk | |
|
2024-12-02
| ||
| 22:45 | use typedef inside main check-in: e80b4c427f user: nnz tags: trunk | |
Changes
Modified aoc2024.c
from [a9e75b1bd8]
to [89e5ae23d6].
1 2 3 4 5 6 7 8 9 10 11 12 |
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "aocutils.h"
static int safereport(int *v, int nv) {
int dir = 1; // ascending
if (v[0] > v[1]) dir = -1; // descending
for (int k = 1; k < nv; k++) {
if (v[k-1] == v[k]) return 0;
if (abs(v[k-1] - v[k]) > 3) return 0;
| > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "aocutils.h"
void aoc202403(char *data, [[maybe_unused]] size_t len) {
int sumproducts = 0, term[2];
char *rest = data;
for (;;) {
char *mul = strstr(rest, "mul(");
if (mul) {
rest = mul + 4;
if (isdigit((unsigned char)rest[0])) {
char *err;
term[0] = (int)strtol(rest, &err, 10);
if (*err == ',') {
if (isdigit((unsigned char)err[1])) {
rest = err + 1;
term[1] = (int)strtol(rest, &err, 10);
if (*err == ')') {
sumproducts += term[0] * term[1];
rest = err + 1;
}
}
}
}
} else {
break;
}
}
printf("The sum of the products is {%d}.\n", sumproducts);
}
static int safereport(int *v, int nv) {
int dir = 1; // ascending
if (v[0] > v[1]) dir = -1; // descending
for (int k = 1; k < nv; k++) {
if (v[k-1] == v[k]) return 0;
if (abs(v[k-1] - v[k]) > 3) return 0;
|
| ︙ | ︙ |
Modified aocdailies.c
from [5d832336de]
to [35ec64d3fd].
| ︙ | ︙ | |||
32 33 34 35 36 37 38 39 40 41 |
case 201523: p = aoc201523; break;
case 201524: p = aoc201524; break;
case 201525: p = aoc201525; break;
#endif
case 202401: p = aoc202401; break;
case 202402: p = aoc202402; break;
}
return p;
}
| > | 32 33 34 35 36 37 38 39 40 41 42 |
case 201523: p = aoc201523; break;
case 201524: p = aoc201524; break;
case 201525: p = aoc201525; break;
#endif
case 202401: p = aoc202401; break;
case 202402: p = aoc202402; break;
case 202403: p = aoc202403; break;
}
return p;
}
|
Modified aocdailies.h
from [5cec122fbd]
to [f35543bb9f].
| ︙ | ︙ | |||
32 33 34 35 36 37 38 39 40 | aocfunc aoc201523; aocfunc aoc201524; aocfunc aoc201525; #endif aocfunc aoc202401; aocfunc aoc202402; #endif | > | 32 33 34 35 36 37 38 39 40 41 | aocfunc aoc201523; aocfunc aoc201524; aocfunc aoc201525; #endif aocfunc aoc202401; aocfunc aoc202402; aocfunc aoc202403; #endif |