aoc2025/7_2/main.c
2025-12-08 21:41:49 +01:00

82 lines
No EOL
22 KiB
C

#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <time.h>
//char input[] = ".......S.......\n...............\n.......^.......\n...............\n......^.^......\n...............\n.....^.^.^.....\n...............\n....^.^...^....\n...............\n...^.^...^.^...\n...............\n..^...^.....^..\n...............\n.^.^.^.^.^...^.\n...............\n\0";
char input[] = "......................................................................S......................................................................\n.............................................................................................................................................\n......................................................................^......................................................................\n.............................................................................................................................................\n.....................................................................^.^.....................................................................\n.............................................................................................................................................\n....................................................................^.^.^....................................................................\n.............................................................................................................................................\n...................................................................^...^.^...................................................................\n.............................................................................................................................................\n..................................................................^...^.^.^..................................................................\n.............................................................................................................................................\n.................................................................^...^.....^.................................................................\n.............................................................................................................................................\n................................................................^.^.......^.^................................................................\n.............................................................................................................................................\n...............................................................^.....^.^.^...^...............................................................\n.............................................................................................................................................\n..............................................................^...^.^.^.^...^.^..............................................................\n.............................................................................................................................................\n.............................................................^.^.^.........^.^.^.............................................................\n.............................................................................................................................................\n............................................................^...^.^.^.^.^...^.^.^............................................................\n.............................................................................................................................................\n...........................................................^.^.^.....^.^.^.....^.^...........................................................\n.............................................................................................................................................\n..........................................................^.....^.^.......^.^.^.^.^..........................................................\n.............................................................................................................................................\n.........................................................^.....^.....^...^.^...^...^.........................................................\n.............................................................................................................................................\n........................................................^.....^.^.^.^.^...^.^.....^.^........................................................\n.............................................................................................................................................\n.......................................................^...^...^.^...^.^.^.....^.....^.......................................................\n.............................................................................................................................................\n......................................................^.^.^...^.^.^.^...^.^.....^.^...^......................................................\n.............................................................................................................................................\n.....................................................^...^.^.^.^.^.^.^.^.^.....^.^.^.^.^.....................................................\n.............................................................................................................................................\n....................................................^.^.^.....^.^.^.^.^.^.^.^.^...^.^...^....................................................\n.............................................................................................................................................\n...................................................^.^.^.^.^...^.....^...^.......^.^.....^...................................................\n.............................................................................................................................................\n..................................................^.^.^...^.^.^.....^.^...^.^.^.^...^.^...^..................................................\n.............................................................................................................................................\n.................................................^...^.^.........^...^.^.^...^.....^.^.^...^.................................................\n.............................................................................................................................................\n................................................^.^.^...^...^.^.^.^.^.^...^.^.^...^.^.^.^...^................................................\n.............................................................................................................................................\n...............................................^.^.^.^.....^.^.^.^...^.^...^...^.....^.^.^.^.^...............................................\n.............................................................................................................................................\n..............................................^.^.^.^.^...^.^.....^.^.^.^.^.....^...^.^.^...^.^..............................................\n.............................................................................................................................................\n.............................................^.^.^.^...^.^.......^.^.^.^...^.^.^...^...^...^.^.^.............................................\n.............................................................................................................................................\n............................................^.^.........^.^.^...^...^.^.^.....^.^.^.....^...^.^.^............................................\n.............................................................................................................................................\n...........................................^.^.....^.^.^.^.^.^...^.^...^.^.^.....^.......^...^.^.^...........................................\n.............................................................................................................................................\n..........................................^.^.......^.^.^.....^.^.....^.................^.^.^.^.^.^..........................................\n.............................................................................................................................................\n.........................................^...^.^.^...^...^.^.^.^.^...^.^.^.....^.^.^...^.^.^.^.^...^.........................................\n.............................................................................................................................................\n........................................^.^...^.....^.^.......^.^...^.......^...^.^.^.^.^...^...^.^.^........................................\n.............................................................................................................................................\n.......................................^.^.^.^.....^.^.^...^...^.^.^.^.^.^.^.^.^...^.^.....^.^.^.^.^.^.......................................\n.............................................................................................................................................\n......................................^.^.........^.....^.^.^.....^.^...^...........^.^.^.^.......^.^.^......................................\n.............................................................................................................................................\n.....................................^...^...^.....^.^.^.....^.^.^...^.....^.^.^.^.^.^.^.^...^.^.^.....^.....................................\n.............................................................................................................................................\n....................................^.......^.^.^.^...^...^.^.^.^.^.^.^.^.^.^.^...^.^...^...^...^...^.^.^....................................\n.............................................................................................................................................\n...................................^...^.^.^.^.^...^...^.^.^.^.^...^.^.^...^...^.^...^.^.^.^.^...^.^.^.^.^...................................\n.............................................................................................................................................\n..................................^.^.^.^.^...^.^.^...^...^.^.^.^.^.^...^.^.......^.....^.^.^.^.......^.^.^..................................\n.............................................................................................................................................\n.................................^...^.^.^.^.^.^.^.^.^...^.....^.^.^.^.^...^.^.....^.^.^.^...^.^.^.....^.^.^.................................\n.............................................................................................................................................\n................................^...^.^...^.^.^.........^.^.^.....^.^.....^...^.^.^.^.^.^...^.^.^...^.^.^.^.^................................\n.............................................................................................................................................\n...............................^.^.^.....^.^...^.^.^.^...^.^.^.^.^...^.^.^.^.^.^.^.....^.^.^...^.^.^...^.^.^.^...............................\n.............................................................................................................................................\n..............................^.^...^.^.^...^.^.^.^.^...^...^.....^...^.^.^.....^.....^.^.^.^.....^.^.^.^.^...^..............................\n.............................................................................................................................................\n.............................^.......^.^.^...^.^...^.^.^.^.^.....^.^.........^.^.^...^.^.^.^.^.^.^.^.......^.^.^.............................\n.............................................................................................................................................\n............................^.^...^.^.^.....^.^.......^.^.^...^.^...^.^.....^.^...^.....^...^.^.^.^.^...^.^...^.^............................\n.............................................................................................................................................\n...........................^...^.^.^.......^.^...^.^.^.^.^.^.....^...^...^.^.^.^.....^.^.^...^.^.^...^.^.....^...^...........................\n.............................................................................................................................................\n..........................^.......^...^.^.^...^.^.^.^...^.^...^.^.^.^.^.^.^...^...^.^...^.....^...^.....^.^...^...^..........................\n.............................................................................................................................................\n.........................^.^.^.^.^.....^...^.^.^...^...^.^...^...^.^...^.^.^.^.....^...^...^.^.^...^...^.^.^.^.^.^.^.........................\n.............................................................................................................................................\n........................^.^...^.^.^.....^.^...^.^.^.^.^...^.^.^.^.^...^.....^.....^.^.^.^.^.^.^...^...^...^.^.^...^.^........................\n.............................................................................................................................................\n.......................^.^.^.^.^...^.^.......^.......^.^.^.^.....^...^.^.^.....^.^.^.......^.^.^...^...^.^.^.^.^.^.^.^.......................\n.............................................................................................................................................\n......................^.....^.^.......^.^.....^.^.^.^.^...^.....^.^.^.^.^.^.^.^.....^...^.^.^.....^...^.........^.^.^.^......................\n.............................................................................................................................................\n.....................^.^.^...^.^...^.^.^.^...^...^.^.^...^.....^.^.....^.^.....^.^.........^.^...^.^.^.^.^.^.....^.^.^.^.....................\n.............................................................................................................................................\n....................^.^.^.^.^...^...........^...^...^...^...^.^...^...^.....^.^.....^.^.....^.^.^.^.^.^.^...^.^.^.....^.^....................\n.............................................................................................................................................\n...................^.^...^.^...^...........^.^.^.^.^.^...^.^.....^.^.....^.....^.^.^...^.^.^.^.^...^.^.....^...^.^...^.^.^...................\n.............................................................................................................................................\n..................^.^.....^.............^.^.^.^.^.^.^.^.^.^...^...^.^...^.^.^.^.^.^.^.^.^.^.^.^.^.^...^.....^.......^...^.^..................\n.............................................................................................................................................\n.................^.....^...^.^...^...^.^...^.^.^...^...^.^.^.^.....^.^.^...^.^.^.^.^...^.^.^.^.....^.....^...^...^.^...^.^.^.................\n.............................................................................................................................................\n................^.^.^.^.....^...^...^.^...^.^...^.^...^.^.....^.^.^.^...^.^.^.............^.^...^.^.........^.^.^...^.^.^.^.^................\n.............................................................................................................................................\n...............^.^.^.^.^.^.^.^.^.^.^.^.^.^...^.^.^.^.^.^.........^.^.^.^...^.^.^.^.^...^...........^...^...^.^.^.^.....^...^.^...............\n.............................................................................................................................................\n..............^.....^.^...^.^.....^.^...^.^.^.^.^...^.^...^...^.^...^.......^.^...^.......^.^.....^.^...^.....^.......^.^.^.^.^..............\n.............................................................................................................................................\n.............^.^.^.^.^.^.^.^.^.^.^.^.^.^.^...^.^.^.^...^.....^.^...^.^.^.....^.^.^.^.^...^.^.^.^.^.^.^...^.^.^...^.^.^.^.^.^.^.^.............\n.............................................................................................................................................\n............^.^.^.^.^.^...^...^...........^.^.^.^.^.^.^...^.^...^...^...^.^.^.^.........^.^...^.^.^.^.^.^.^...^.....^.......^.^.^............\n.............................................................................................................................................\n...........^.^.....^.^.^.^.^.^.^.^...^.^.^.^.^...^.^.^.....^.^.^.^.^...^.......^...^.^.^.^.....^...^.^.^.^.^.....^.^.^.^.^...^.^.^...........\n.............................................................................................................................................\n..........^.^.^.^.^.^.^...^.....^.^.^...^.^.^...^...^.^.^.^.^.^.^.......^.^.......^.^.^.^.^.....^.^.^.^.^.^.....^.^...^.^...^.^.^.^..........\n.............................................................................................................................................\n.........^.....^.^.^.^...^...^...^...^.^...^.^.......^.^.^.^.^...^.^.^.....^.^.^.^.......^.^.^...^.^.^.^.^.......^...^.....^.^...^.^.........\n.............................................................................................................................................\n........^.^...^.^.^.^.^.^.....^...^.....^.^.^...^...^...^.^.^...^.^.^...^.^.....^...^.....^.^.^.^...^...^.^.^.^.....^.^.^...^.....^.^........\n.............................................................................................................................................\n.......^...^...^.^.^.....^.^...^...^.^.....^...^...^.^.^.^.^...^.^...^.^.^.^.....^.^.^...^.^.^...^.^...^.^.^.....^.^.^.^...^.^.^.^.^.^.......\n.............................................................................................................................................\n......^...........^.^.^.^.....^.^.^.^...^...............^.^.......^.^...^.^.^.^.....^...^...^.^.^.^.^...^.^...^.^.^.........^...^.^.^.^......\n.............................................................................................................................................\n.....^.^.^.^...^.^.^.^.^.^...^.......^.^...^.^.^.^.....^.^.^.^.^.^.^.^.^.^.^...^.^.....^.^.^...^.^...^.......^.^...^.^...^.^.^...^.^.^.^.....\n.............................................................................................................................................\n....^.^.^...^...^...^.^.^.^...^.^.......^.....^.....^...^.^...^...^.^.^.^.^.......^.^.^...^.^.^.....^.^.^...^...^.^.^.^.^...^.......^...^....\n.............................................................................................................................................\n...^.^.....^.^.^...^...^.^.^...^.^.^.^...^...^...^.^.^.^...^.^.^.^.^.^...^.^...^.^.^...^.....^.^.^...^.^.^...^.^.^.^.^.......^.^...^.^.^.^...\n.............................................................................................................................................\n..^.^.^.^...^.^.^.^...^.^.^.^.^.^.^...^...^.^.^.^...^.....^...^.^.^.^.^.^...^...^.^.^.^.....^.......^.^.^.^.^.....^.^.^.^.^.........^.^...^..\n.............................................................................................................................................\n.^.^.^.^.^.^.^.^.^...^.^.^...^...^.....^.^.....^.^.^.^.^.^...^...^.^...^.^.^.^.^...^.^.^.^...^.^.^.^...^...^...^...^.^.^.^.....^.^.^.....^.^.\n.............................................................................................................................................\n\0";
int main(int argc, char *argv[]){
clock_t start, end;
start = clock();
uint64_t count = 0;
for(int t = 0; t<10000; t++){
int width = 0;
int height = 0;
count = 0;
while(true){
if(input[width] == '\n')
{
break;
}
width++;
}
//printf("width: %d\n", width);
int i = 0;
while(input[i] != 0){
if(input[i] == '\n'){
height++;
}
i++;
}
uint64_t values[height*width/2];
memset(values, 0, height*width*4);
uint64_t* rows[height/2];
for(int i = 0; i<height/2; i++){
rows[i] = &values[width*i];
}
for(int o = 0; o < width; o++){
char element = input[o];
if(element == 'S'){
rows[0][o] = 1;
}
}
for(int i = 0; i < height/2; i++){
for(int o = 0; o < width; o++){
uint64_t number = rows[i][o];
char element = input[ (width+1) * ((i+1)*2) + o];
switch(element){
case '^':
rows[i+1][o+1] += number;
rows[i+1][o-1] += number;
break;
case '.':
rows[i+1][o] += number;
break;
}
}
}
for(int i = 0; i<width; i++){
count += rows[height/2-1][i];
}
}
end = clock();
printf("count: %lu\n", count);
clock_t ticks_taken = end - start;
double time_taken = ((double)ticks_taken)/CLOCKS_PER_SEC;
printf("time take: %f ticks\n", time_taken);
printf("CLOCKS_PER_SEC: %ld\n", CLOCKS_PER_SEC);
exit(1);
}