advent2025

Advent of Code 2025 Solutions
git clone git://bsandro.tech/advent2025
Log | Files | Refs | LICENSE

commit b4766bd83a5a6a8673e34578a6ca93bfe0ea424c
parent 72036c6737f5a82db7241c7717d816e9e37a90d0
Author: bsandro <email@bsandro.tech>
Date:   Tue,  9 Dec 2025 21:30:28 +0200

removed .pbm generation code

Diffstat:
Mday09.c | 79-------------------------------------------------------------------------------
1 file changed, 0 insertions(+), 79 deletions(-)

diff --git a/day09.c b/day09.c @@ -1,14 +1,7 @@ -#define _GNU_SOURCE -#define __USE_GNU 1 -#include <errno.h> -#include <unistd.h> -#include <fcntl.h> #include <stdio.h> #include <inttypes.h> #include <stdlib.h> -#include <math.h> #include <stdbool.h> -#include <string.h> #include "cputime.h" #define MAX(a,b) (((a)>(b))?(a):(b)) @@ -113,76 +106,6 @@ static int get_max_x(int points_l, Point points[points_l]) { return maxx; } -void gen_pbm(int lines_l, Line lines[lines_l]) { - Point min = {0}; - Point max = {0}; - for (int i=0;i<lines_l;++i) { - if (lines[i].p1.x<min.x) min.x=lines[i].p1.x; - if (lines[i].p2.x<min.x) min.x=lines[i].p2.x; - if (lines[i].p1.y<min.y) min.y=lines[i].p1.y; - if (lines[i].p2.y<min.y) min.y=lines[i].p2.y; - if (lines[i].p1.x>max.x) max.x=lines[i].p1.x; - if (lines[i].p2.x>max.x) max.x=lines[i].p2.x; - if (lines[i].p1.y>max.y) max.y=lines[i].p1.y; - if (lines[i].p2.y>max.y) max.y=lines[i].p2.y; - } - int w = max.x+3; //-min.x; - int h = max.y+3; //-min.y; - printf("%dx%d\n",w,h); - int f = open("day09.pbm", O_CREAT | O_WRONLY | O_TRUNC, 0666); - //fcntl(f, F_NOCACHE, 1); - char header[64] = {0}; - int n = snprintf(header, sizeof(header), "P1\n%d %d\n", w, h); - if (write(f, header, n)!=n) { - printf("error: %d\n", errno); - exit(1); - } - puts("header write ok"); - size_t len = sizeof(char)*w*h; - printf("size: %zu\n", len); - char *pic = malloc(len); - if (pic==NULL) { printf("error: %d\n", errno); exit(1); } - memset(pic, '0', len); - puts("malloc ok"); - for (int i=0;i<lines_l;++i) { - Point p1 = lines[i].p1; - Point p2 = lines[i].p2; - if (p1.x==p2.x) { - int miny = MIN(p1.y, p2.y); - int maxy = MAX(p1.y, p2.y); - for (int y=miny;y<=maxy;++y) { - size_t offset = (size_t)y*w + p1.x; - if (offset>=len) { printf("invalid offset y %zu\n", offset); exit(1); } - pic[offset] = '1'; - } - } else if (p1.y==p2.y) { - int minx = MIN(p1.x, p2.x); - int maxx = MAX(p1.x, p2.x); - for (int x=minx;x<=maxx;++x) { - size_t offset = ((size_t)p1.y*w) + x; - if (offset >= len) { - printf("invalid offset x %zu (y=%d,w=%d,minmax=%d-%d,x=%d,len=%zu,t=%zu)\n", offset, p1.y,w,minx,maxx,x,len, ((size_t)p1.y*w)+x); - exit(1); - } - pic[offset] = '1'; - } - } - } - puts("pic generate ok"); - //fsync(f); - //if (write(f, pic, len) != (int)len) ("error writing file"); - size_t chunk = sizeof(char) * 1024 * 1024 * 10; - if (chunk>len) chunk=len; - printf("chunk: %zu\n", chunk); - for (size_t i=0;i<len;i += chunk) { - if (len!=chunk && len/chunk == 0) chunk = len%chunk; - printf("write chunk %zu of size %zu (real %d)\n", i, chunk, n); - n = write(f, pic+i, chunk); - } - fsync(f); - close(f); -} - int main(void) { int64_t part1 = 0; int64_t part2 = 0; @@ -214,8 +137,6 @@ int main(void) { lines[lines_l++] = (Line){ points[i], points[i+1] }; } lines[lines_l++] = (Line){ points[0], points[points_l-1] }; - //gen_pbm(lines_l, lines); - (void)gen_pbm; int squares_max = (points_l*points_l-points_l)/2; int64_t squares[squares_max]; int squares_l = 0;