Advent of Code

Check-in [cf1a1232c2]
Login

Check-in [cf1a1232c2]

Overview
Comment:changed empty values again to work with part two
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: cf1a1232c27b93704dd040afdecc8c137e667fa496b5dc6d977e596206dc1f21
User & Date: nnz on 2024-12-09 12:52:07
Other Links: manifest | tags
Context
2024-12-09
18:06
202409 2nd star check-in: f303335c22 user: nnz tags: trunk
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
Changes

Modified aoc2024.c from [694ae36748] to [1b7a71a647].

20
21
22
23
24
25
26
27

28
29
30
31
32
33
34
20
21
22
23
24
25
26

27
28
29
30
31
32
33
34







-
+







    while (*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++] = fileid;
            disk[ndisk++] = (fileid * 10) + (*data - '0'); // encode fileid and length
        }
        fileid++;
        data++;
        if (*data) {
            for (int k = 0; k < *data - '0'; k++) {
                if (ndisk == rdisk) {
                    // assume it works
53
54
55
56
57
58
59
60

61
62
63
64
65
66
67
53
54
55
56
57
58
59

60
61
62
63
64
65
66
67







-
+







        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;
        chksum += ((size_t)disk[index]/10) * index;
        index++;
    }
    printf("%llu\n", chksum);
    free(disk);

    // part 2
    free(diskcopy);