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

70 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 width = 0;
int height = 0;
int main(int argc, char *argv[]){
clock_t start, end;
start = clock();
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++;
}
int count = 0;
for(int i = 0; i < height-1; i++){
for(int o = 0; o < width; o++){
char element = input[(width+1)*i+o];
switch(element){
case 'S':
input[(width+1)*(i+1)+o] = '|';
break;
case '^':
if(input[(width+1)*(i-1)+o] == '|'){
input[(width+1)*(i)+o] = 'v';
input[(width+1)*(i+1)+o+1] = '|';
input[(width+1)*(i+1)+o-1] = '|';
count++;
}
break;
case '|':
if(input[(width+1)*(i+1)+o] != '^')
input[(width+1)*(i+1)+o] = '|';
break;
}
}
//printf(input);
//printf("count: %d\n", count);
}
end = clock();
printf("count: %d\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);
}