Overview
Comment: | moved and renamed function to aocutils.c |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
682dabca63bc14b37cd47be3614fac3d |
User & Date: | nnz on 2024-12-06 12:05:25 |
Other Links: | manifest | tags |
Context
2024-12-06
| ||
12:56 | 202406 1st star check-in: a114787839 user: nnz tags: trunk | |
12:05 | moved and renamed function to aocutils.c check-in: 682dabca63 user: nnz tags: trunk | |
2024-12-05
| ||
21:10 | inputs are now in their directory check-in: 72ebf0375e user: nnz tags: trunk | |
Changes
Modified aoc2024.c from [bb8df23888] to [9785441a22].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | 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 | + + + + + + + + | #include <ctype.h> #include <stdbool.h> #include <stddef.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include "aocdailies.h" #include "aocutils.h" /* === aoc202406 ======================================================= Hmmm, I've done something like this already this year... on day 4 I need rcmap() moved to aocutils ... done; now it's called `linearize2d` ===================================================================== */ void aoc202406(char *data, size_t len) { (void)data; (void)len; } /* === aoc202405 ======================================================= ===================================================================== */ static int ppcmp(unsigned a, unsigned b, unsigned (*r)[2], size_t nr) { for (size_t k = 0; k < nr; k++) { if ((a == r[k][0]) && (b == r[k][1])) return -1; if ((a == r[k][1]) && (b == r[k][0])) return 1; } return 0; |
︙ | |||
79 80 81 82 83 84 85 | 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 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | - - + + - - - - + + + - + - - - - - - - - - + + + + + + + + + - - - - + + + + + + + | } accumsum += accum; } while ((line = strtok(NULL, "\n")) != NULL); printf("The sum of middle update numbers is {%u}.\n", accumsum); printf("The sum of middle update numbers for newly ordered updates is {%u}.\n", accumsum2); } |
︙ | |||
199 200 201 202 203 204 205 206 207 208 209 210 211 212 | 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | + + + | break; } } printf("The sum of the products is {%u}.\n", sumproducts); printf("The sum of the products with conditionals is {%u}.\n", sumproducts2); } /* === aoc202402 ======================================================= ===================================================================== */ static bool safereport(unsigned *v, size_t nv) { int dir = 1; // ascending if (v[0] > v[1]) dir = -1; // descending for (size_t k = 1; k < nv; k++) { if (v[k-1] == v[k]) return false; if (distance(v[k-1], v[k]) > 3) return false; if (dir == -1) { |
︙ | |||
243 244 245 246 247 248 249 250 251 252 253 254 255 256 | 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | + + + | } free(arr); line = strtok(NULL, "\n"); } printf("There are %u safe reports.\n", safe); printf("There are %u safe reports with the Problem Dampener.\n", safe2); } /* === aoc202401 ======================================================= ===================================================================== */ static int delta(const void *a, const void *b) { const unsigned *aa = a; const unsigned *bb = b; if (*aa > *bb) return 1; if (*aa < *bb) return -1; return 0; |
︙ |
Modified aocutils.c from [2b60469d03] to [ff66d0a337].
1 2 3 4 5 6 7 8 9 10 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | + + + + | #include <stdio.h> #include <stdlib.h> #include "aocutils.h" size_t linearize2d(unsigned width, unsigned row, unsigned col) { return (row * width) + col; } size_t text2array(unsigned **dst, const char *r) { unsigned *a = malloc(512 * sizeof *a); size_t na = 0, sa = 512; char *err; unsigned v; for (;;) { |
︙ |
Modified aocutils.h from [b9fb3ba61b] to [475433f577].
1 2 3 4 5 6 7 8 9 10 | 1 2 3 4 5 6 7 8 9 10 11 | + | #ifndef AOCUTILS_H_INCLUDED #define AOCUTILS_H_INCLUDED size_t linearize2d(unsigned width, unsigned row, unsigned col); size_t text2array(unsigned **dst, const char *txt); size_t slurp(char **dst, const char *filename); unsigned distance(unsigned a, unsigned b); unsigned max3u(unsigned a, unsigned b, unsigned c); unsigned min3u(unsigned a, unsigned b, unsigned c); #endif |