Overview
| Comment: | changed empty values to work with part two |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | trunk |
| Files: | files | file ages | folders |
| SHA3-256: |
c93635c614757d7347a13a91a745d643 |
| User & Date: | nnz on 2024-12-09 12:24:52.362 |
| Other Links: | manifest | tags |
Context
|
2024-12-09
| ||
| 12:52 | changed empty values again to work with part two check-in: cf1a1232c2 user: nnz tags: trunk | |
| 12:24 | changed empty values to work with part two check-in: c93635c614 user: nnz tags: trunk | |
| 11:50 | 202409 1st star check-in: 8682072363 user: nnz tags: trunk | |
Changes
Modified aoc2024.c
from [3ba7100c1a]
to [694ae36748].
| ︙ | ︙ | |||
31 32 33 34 35 36 37 |
if (*data) {
for (int k = 0; k < *data - '0'; k++) {
if (ndisk == rdisk) {
// assume it works
rdisk = (13*rdisk)/8;
disk = realloc(disk, rdisk * sizeof *disk);
}
| | > > > > | | > > > | 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
if (*data) {
for (int k = 0; k < *data - '0'; k++) {
if (ndisk == rdisk) {
// assume it works
rdisk = (13*rdisk)/8;
disk = realloc(disk, rdisk * sizeof *disk);
}
disk[ndisk++] = -1 * (*data - '0');
}
data++;
}
}
// copy disk
int *diskcopy = malloc(ndisk * sizeof *disk);
memcpy(diskcopy, disk, ndisk * sizeof *disk);
int *left = disk, *right = disk + ndisk;
for (;;) {
while (*left >= 0) left++;
if (left >= right) break;
while (right[-1] < 0) right--;
// swap *left and right[-1]
int tmp = *--right;
*right = *left;
*left++ = tmp;
}
unsigned long long chksum = 0;
size_t index = 0;
while (disk[index] >= 0) {
chksum += (size_t)disk[index] * index;
index++;
}
printf("%llu\n", chksum);
free(disk);
// part 2
free(diskcopy);
}
/* === aoc202408 =======================================================
Oh! another square of text!
Idea: for all points p with an antenna find all points q>p with
a corresponding frequency. For each such pair calculate the 2 antinodes
and add the resulting points (if not there already) to an array.
|
| ︙ | ︙ |