From aec1c07260257ba7c28eff53f422ddb7daaf316a Mon Sep 17 00:00:00 2001 From: kartofen Date: Sun, 31 Jul 2022 11:46:17 +0300 Subject: Big Bang --- Advent-of-Code-2021/AOC-25/aoc-25.c | 154 ++++++++++++++++++++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 Advent-of-Code-2021/AOC-25/aoc-25.c (limited to 'Advent-of-Code-2021/AOC-25/aoc-25.c') diff --git a/Advent-of-Code-2021/AOC-25/aoc-25.c b/Advent-of-Code-2021/AOC-25/aoc-25.c new file mode 100644 index 0000000..089b141 --- /dev/null +++ b/Advent-of-Code-2021/AOC-25/aoc-25.c @@ -0,0 +1,154 @@ +#include +#include +#include +#include +#include +#include + +#define XLEN 139 //10 +#define YLEN 137 //9 +#define LEN (XLEN * YLEN) + +typedef struct Sea_cuc_move { + int from_pos; + int to_pos; +} Sea_cuc_move; + +char map[LEN]; +char map_bak[LEN]; + +void ParseInput(char *filepath) +{ + char ch; + FILE *fp; + fp = fopen(filepath, "r"); + + if(fp == NULL) + { + fprintf(stderr, "ERROR: something with file idk what fuck you"); + exit(EXIT_FAILURE); + } + + int i = 0; + while((ch = fgetc(fp)) != EOF) + { + if(ch == '\n') continue; + + map[i] = ch; + i++; + } + + fclose(fp); +} + +void Move(char type, Sea_cuc_move pos) +{ + map[pos.from_pos] = '.'; + map[pos.to_pos] = type; +} + +void MoveEast() +{ + Sea_cuc_move positions_east[5000]; + int cucs_east = 0; + + for(int i=0; i') + { + int x = i % XLEN; + if(x == (XLEN-1)) + { + if(map[i - x] != '.') + continue; + + positions_east[cucs_east] = (Sea_cuc_move){i, i - x}; + cucs_east += 1; + } + else if(map[i+1] == '.') + { + positions_east[cucs_east] = (Sea_cuc_move){i, i + 1}; + cucs_east += 1; + } + + } + } + + assert(cucs_east < 5000); + + if(cucs_east != 0) + for(int i=0; i', positions_east[i]); +} + +void MoveSouth() +{ + Sea_cuc_move positions_south[5000]; + int cucs_south = 0; + + for(int i=0; i