Overview
| Comment: | 202407 -- answer too low, maybe got some overflowing |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | trunk |
| Files: | files | file ages | folders |
| SHA3-256: |
5cddab1bb6baa9b7e59b622599fcfcfa |
| User & Date: | nnz on 2024-12-07 09:35:52.445 |
| Other Links: | manifest | tags |
Context
|
2024-12-07
| ||
| 09:40 | 202407 1st star check-in: 965ad94c16 user: nnz tags: trunk | |
| 09:35 | 202407 -- answer too low, maybe got some overflowing check-in: 5cddab1bb6 user: nnz tags: trunk | |
|
2024-12-06
| ||
| 16:45 | not that it matters, but bug squashed check-in: aec632be32 user: nnz tags: trunk | |
Changes
Modified aoc2024.c
from [8003dbb812]
to [ef2e69e998].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | #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` Part Two: brute force? It likely is faster than coming up with an algo Let's go: save map, for every available position put in an obstacle, loop around until some place is visited 4? times or area is exited | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 |
#include <ctype.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "aocdailies.h"
#include "aocutils.h"
/* === aoc202407 =======================================================
Part one looks easy
===================================================================== */
static bool canbetrue(unsigned v, unsigned *a, size_t n) {
// for startes let's assume no overflowing
if (n == 1) return (v == *a);
unsigned tmp = a[1];
a[1] = a[0] + tmp;
if (canbetrue(v, a+1, n-1)) return true;
a[1] = a[0] * tmp;
if (canbetrue(v, a+1, n-1)) return true;
a[1] = tmp;
return false;
}
void aoc202407(char *data, size_t len) {
(void)len; // unused argument
unsigned calibrationtotal = 0;
char *line = strtok(data, "\n");
unsigned number[50], nnumber, maxn = 0;
while (line) {
char *err;
unsigned testvalue = strtoul(line, &err, 10);
err += 1; // skip ':'
nnumber = 0;
while (*err == ' ') {
number[nnumber++] = strtoul(err, &err, 10);
}
if (canbetrue(testvalue, number, nnumber)) calibrationtotal += testvalue;
if (nnumber > maxn) { maxn = nnumber; printf("max: %u\n", maxn); }
line = strtok(NULL, "\n");
}
printf("The calibration total is {%u}.\n", calibrationtotal);
}
/* === 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`
Part Two: brute force? It likely is faster than coming up with an algo
Let's go: save map, for every available position put in an obstacle,
loop around until some place is visited 4? times or area is exited
|
| ︙ | ︙ |
Modified aocdailies.c
from [e95e69a444]
to [e5e3eb3466].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
#include <stddef.h>
#include "aocdailies.h"
aocfunc *aocselect(unsigned y, unsigned d) {
aocfunc *p;
switch (y * 100 + d) {
default: p = NULL; break;
case 202406: p = aoc202406; break;
case 202405: p = aoc202405; break;
case 202404: p = aoc202404; break;
case 202403: p = aoc202403; break;
case 202402: p = aoc202402; break;
case 202401: p = aoc202401; break;
| > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
#include <stddef.h>
#include "aocdailies.h"
aocfunc *aocselect(unsigned y, unsigned d) {
aocfunc *p;
switch (y * 100 + d) {
default: p = NULL; break;
// YYYYdd ==> aocYYYYdd
case 202407: p = aoc202407; break;
case 202406: p = aoc202406; break;
case 202405: p = aoc202405; break;
case 202404: p = aoc202404; break;
case 202403: p = aoc202403; break;
case 202402: p = aoc202402; break;
case 202401: p = aoc202401; break;
|
| ︙ | ︙ |
Modified aocdailies.h
from [730fdd33bd]
to [e05094a8ab].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | #ifndef AOCDAILIES_H_INCLUDED #define AOCDAILIES_H_INCLUDED #include <stddef.h> typedef void aocfunc(char *, size_t); aocfunc *aocselect(unsigned, unsigned); aocfunc aoc202406; aocfunc aoc202405; aocfunc aoc202404; aocfunc aoc202403; aocfunc aoc202402; aocfunc aoc202401; | > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | #ifndef AOCDAILIES_H_INCLUDED #define AOCDAILIES_H_INCLUDED #include <stddef.h> typedef void aocfunc(char *, size_t); aocfunc *aocselect(unsigned, unsigned); aocfunc aoc202407; aocfunc aoc202406; aocfunc aoc202405; aocfunc aoc202404; aocfunc aoc202403; aocfunc aoc202402; aocfunc aoc202401; |
| ︙ | ︙ |