Overview
| Comment: | 202409 2nd star |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | trunk |
| Files: | files | file ages | folders |
| SHA3-256: |
f303335c22e1c9e68d5467dd70c1f9b8 |
| User & Date: | nnz on 2024-12-09 18:06:52.092 |
| Other Links: | manifest | tags |
Context
|
2024-12-15
| ||
| 11:18 | 201504 two stars check-in: 17bcf7e37c user: nnz tags: trunk | |
|
2024-12-11
| ||
| 14:28 | I have been working on this for some time check-in: 235f764371 user: nnz tags: md5mini | |
|
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 | |
Changes
Modified aoc2024.c
from [1b7a71a647]
to [1416b27373].
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 | 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 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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | + + + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |
#include <ctype.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "aocdailies.h"
#include "aocutils.h"
/* === aoc202409 =======================================================
WOW! input consists of a 20,000 long string of numbers!
Make an array of blocks, each with either -1 or the fileid
For Part Two: make an array of blocks with the encoded value of
(fileid * 10) + length, or, when empty, the negative length
===================================================================== */
void aoc202409(char *data, size_t len) {
(void)len; // unused argument
int *disk = malloc(512 * sizeof *disk);
size_t rdisk = 512;
size_t ndisk = 0;
int fileid = 0;
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);
}
|
| ︙ |