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-2/aoc-2 | Bin 0 -> 16568 bytes Advent-of-Code-2021/AOC-2/aoc-2.c | 104 ++++ Advent-of-Code-2021/AOC-2/aoc-2.c~ | 0 Advent-of-Code-2021/AOC-2/input-2.txt | 1000 ++++++++++++++++++++++++++++++++ Advent-of-Code-2021/AOC-2/input-2.txt~ | 0 5 files changed, 1104 insertions(+) create mode 100755 Advent-of-Code-2021/AOC-2/aoc-2 create mode 100644 Advent-of-Code-2021/AOC-2/aoc-2.c create mode 100644 Advent-of-Code-2021/AOC-2/aoc-2.c~ create mode 100644 Advent-of-Code-2021/AOC-2/input-2.txt create mode 100644 Advent-of-Code-2021/AOC-2/input-2.txt~ (limited to 'Advent-of-Code-2021/AOC-2') diff --git a/Advent-of-Code-2021/AOC-2/aoc-2 b/Advent-of-Code-2021/AOC-2/aoc-2 new file mode 100755 index 0000000..c15492c Binary files /dev/null and b/Advent-of-Code-2021/AOC-2/aoc-2 differ diff --git a/Advent-of-Code-2021/AOC-2/aoc-2.c b/Advent-of-Code-2021/AOC-2/aoc-2.c new file mode 100644 index 0000000..6c212b1 --- /dev/null +++ b/Advent-of-Code-2021/AOC-2/aoc-2.c @@ -0,0 +1,104 @@ +#include +#include +#include + +int pos = 0; +int depth = 0; +int aim = 0; + +void ParseInput(char *filepath) +{ + char ch; + FILE *fp; + fp = fopen(filepath, "r"); + + if (fp == NULL) + { + perror("Error while opening the file.\n"); + exit(EXIT_FAILURE); + } + + char command; + char char_x_val; + int current_type = 0; // 0 - command; 1 - skip; 2 - val + /* Part 1 + while((ch= fgetc(fp)) != EOF) + { + if(ch == ' ') + { + current_type = 2; + } + else if(ch == '\n') + { + int x = atoi(&char_x_val); + switch(command) + { + case 'f': + pos += x; + break; + case 'd': + depth += x; + break; + case 'u': + depth -= x; + } + + current_type = 0; + } + else if(current_type == 0) + { + command = ch; + current_type = 1; + } + else if(current_type == 2) + { + char_x_val = ch; + } + } + */ + + /* Part2 */ + while((ch= fgetc(fp)) != EOF) + { + if(ch == ' ') + { + current_type = 2; + } + else if(ch == '\n') + { + int x = atoi(&char_x_val); + switch(command) + { + case 'f': + pos += x; + depth += aim * x; + break; + case 'd': + aim += x; + break; + case 'u': + aim -= x; + } + + current_type = 0; + } + else if(current_type == 0) + { + command = ch; + current_type = 1; + } + else if(current_type == 2) + { + char_x_val = ch; + } + } + + fclose(fp); +} + +int main(void) +{ + ParseInput("input-2.txt"); + printf("pos: %d, depth: %d; product: %d", pos, depth, pos * depth); + return 0; +} diff --git a/Advent-of-Code-2021/AOC-2/aoc-2.c~ b/Advent-of-Code-2021/AOC-2/aoc-2.c~ new file mode 100644 index 0000000..e69de29 diff --git a/Advent-of-Code-2021/AOC-2/input-2.txt b/Advent-of-Code-2021/AOC-2/input-2.txt new file mode 100644 index 0000000..c6b3290 --- /dev/null +++ b/Advent-of-Code-2021/AOC-2/input-2.txt @@ -0,0 +1,1000 @@ +forward 3 +down 4 +forward 3 +up 4 +down 4 +down 6 +down 3 +down 1 +up 7 +down 7 +forward 4 +forward 7 +forward 3 +down 2 +forward 5 +down 7 +forward 5 +up 9 +down 6 +forward 8 +forward 8 +down 8 +forward 7 +down 9 +down 4 +down 6 +forward 1 +down 2 +down 7 +up 4 +forward 8 +down 5 +down 7 +down 1 +forward 5 +down 1 +up 1 +forward 5 +forward 1 +down 1 +forward 3 +up 4 +up 4 +up 8 +up 1 +forward 7 +down 3 +forward 3 +forward 3 +down 3 +down 6 +down 7 +forward 4 +down 2 +up 3 +forward 5 +forward 1 +down 3 +up 3 +up 4 +forward 2 +forward 6 +up 1 +down 9 +up 3 +forward 5 +forward 2 +up 9 +up 2 +down 5 +down 5 +forward 7 +forward 1 +down 7 +forward 9 +forward 8 +down 7 +forward 5 +forward 4 +down 5 +forward 7 +forward 3 +down 2 +forward 2 +forward 2 +down 1 +up 8 +down 2 +down 2 +forward 6 +up 9 +forward 6 +up 6 +forward 5 +forward 5 +down 2 +forward 5 +up 5 +forward 5 +up 4 +down 1 +up 5 +down 2 +forward 3 +down 1 +forward 2 +up 4 +down 6 +forward 1 +forward 6 +forward 6 +forward 8 +forward 8 +forward 3 +forward 5 +down 8 +up 8 +down 6 +down 8 +forward 8 +down 6 +forward 4 +down 4 +forward 7 +forward 9 +down 6 +up 6 +forward 6 +down 9 +up 7 +up 9 +down 1 +up 5 +forward 2 +forward 3 +up 6 +forward 8 +forward 7 +down 4 +up 8 +up 2 +down 2 +up 3 +down 2 +down 8 +forward 9 +up 9 +forward 7 +down 9 +forward 4 +forward 3 +forward 2 +down 5 +forward 3 +forward 1 +down 2 +forward 3 +down 7 +down 8 +forward 9 +down 9 +forward 2 +up 5 +up 2 +down 8 +down 1 +down 7 +forward 6 +down 2 +forward 9 +down 6 +down 9 +forward 9 +down 2 +up 5 +forward 2 +down 7 +down 6 +up 1 +forward 9 +up 7 +down 1 +forward 5 +down 5 +up 2 +forward 6 +forward 2 +up 9 +up 7 +down 2 +down 1 +forward 6 +down 2 +forward 9 +forward 8 +forward 2 +up 1 +down 7 +down 7 +forward 5 +forward 9 +down 5 +down 5 +down 5 +forward 4 +up 4 +down 7 +up 6 +forward 3 +up 5 +forward 3 +forward 6 +forward 8 +down 6 +forward 4 +forward 5 +up 8 +down 9 +down 3 +down 8 +forward 8 +forward 1 +down 7 +down 2 +forward 8 +forward 7 +up 2 +down 9 +forward 2 +down 6 +down 7 +up 2 +up 7 +down 6 +down 8 +down 2 +forward 8 +down 6 +up 1 +down 6 +down 5 +down 8 +down 1 +down 4 +down 1 +down 8 +up 3 +forward 1 +forward 5 +forward 2 +forward 2 +down 5 +down 2 +down 8 +up 7 +forward 2 +forward 1 +forward 4 +up 4 +down 5 +up 4 +down 8 +up 5 +down 6 +down 8 +down 8 +forward 8 +forward 5 +down 1 +down 2 +down 4 +forward 5 +up 3 +forward 3 +down 7 +forward 9 +down 9 +down 5 +forward 5 +down 9 +forward 9 +down 5 +up 4 +up 9 +forward 1 +forward 6 +forward 9 +forward 2 +up 5 +forward 9 +down 8 +up 2 +up 9 +forward 1 +down 7 +down 4 +down 4 +up 3 +forward 6 +down 1 +forward 6 +forward 3 +up 3 +forward 1 +down 1 +up 8 +up 3 +forward 9 +forward 1 +forward 8 +forward 8 +up 7 +forward 2 +forward 9 +down 9 +down 2 +down 5 +down 1 +forward 9 +forward 9 +up 4 +forward 6 +down 3 +forward 2 +forward 5 +up 4 +forward 2 +up 1 +up 4 +up 3 +up 6 +up 6 +down 2 +up 7 +down 1 +down 3 +forward 3 +up 5 +forward 4 +down 5 +forward 9 +down 2 +up 5 +forward 9 +down 3 +down 5 +forward 3 +forward 7 +forward 9 +up 2 +down 6 +up 6 +down 8 +forward 8 +down 1 +forward 3 +forward 4 +up 6 +up 3 +forward 6 +forward 5 +forward 2 +down 7 +down 1 +down 5 +forward 6 +down 4 +down 2 +forward 7 +up 9 +forward 3 +down 2 +up 3 +down 3 +down 1 +up 5 +down 4 +forward 1 +forward 2 +forward 2 +forward 6 +forward 2 +down 2 +down 8 +down 1 +down 2 +down 7 +up 7 +down 7 +forward 7 +forward 7 +down 8 +forward 1 +down 7 +down 7 +down 8 +up 9 +down 4 +up 6 +forward 7 +up 2 +down 8 +forward 2 +down 8 +forward 4 +down 4 +forward 4 +up 1 +down 2 +forward 6 +forward 7 +forward 8 +down 2 +forward 5 +forward 1 +up 9 +down 8 +down 2 +forward 1 +down 8 +forward 2 +up 2 +up 3 +up 7 +forward 3 +forward 3 +up 3 +up 5 +forward 8 +down 6 +forward 6 +down 2 +down 7 +forward 3 +forward 6 +down 5 +down 6 +up 4 +forward 8 +up 8 +down 9 +forward 7 +forward 1 +down 6 +up 1 +down 7 +forward 4 +forward 8 +down 2 +forward 8 +down 3 +down 5 +down 5 +forward 8 +down 3 +up 8 +down 9 +forward 2 +down 9 +forward 4 +up 8 +forward 4 +up 1 +forward 8 +forward 2 +forward 5 +down 2 +down 6 +up 2 +down 8 +forward 9 +forward 5 +forward 6 +forward 4 +down 4 +down 6 +up 1 +forward 3 +down 6 +forward 6 +forward 1 +forward 6 +forward 9 +up 6 +forward 5 +down 4 +forward 5 +down 8 +down 7 +forward 7 +up 5 +down 6 +forward 4 +forward 6 +forward 5 +up 4 +down 3 +forward 1 +down 1 +forward 6 +up 1 +up 1 +down 7 +forward 5 +forward 1 +down 2 +forward 2 +down 3 +down 6 +down 5 +down 4 +forward 2 +forward 1 +down 7 +forward 9 +up 6 +forward 9 +forward 2 +down 1 +forward 9 +forward 4 +down 1 +forward 3 +up 9 +down 1 +down 3 +down 6 +down 9 +forward 3 +down 8 +down 3 +forward 5 +forward 1 +forward 5 +forward 2 +up 4 +down 6 +up 7 +forward 7 +down 9 +forward 6 +down 4 +down 1 +up 8 +down 4 +forward 7 +forward 5 +down 5 +down 2 +down 1 +down 4 +up 5 +down 8 +forward 1 +forward 2 +down 9 +forward 7 +down 8 +forward 5 +forward 7 +forward 2 +down 6 +down 5 +down 6 +down 7 +forward 2 +up 9 +down 3 +forward 1 +up 6 +forward 4 +down 3 +up 7 +forward 9 +forward 7 +down 4 +up 1 +forward 6 +up 4 +down 1 +down 4 +down 2 +down 5 +down 4 +down 7 +forward 2 +down 8 +down 8 +forward 9 +forward 3 +down 2 +down 2 +forward 2 +down 9 +forward 8 +up 8 +down 3 +forward 4 +down 9 +up 2 +forward 6 +forward 2 +up 6 +up 7 +forward 1 +forward 2 +up 2 +down 8 +forward 9 +down 7 +forward 1 +down 6 +down 8 +forward 2 +down 8 +forward 6 +forward 7 +forward 8 +forward 1 +up 8 +down 5 +forward 8 +down 3 +down 6 +forward 6 +down 4 +down 6 +forward 8 +down 3 +down 4 +forward 6 +forward 1 +up 1 +up 3 +forward 7 +forward 2 +down 1 +down 7 +down 3 +down 4 +down 3 +forward 2 +forward 4 +down 6 +down 2 +forward 3 +down 9 +down 5 +down 6 +down 7 +down 5 +down 3 +forward 5 +forward 6 +down 3 +down 1 +up 3 +down 8 +down 7 +down 5 +up 9 +down 8 +down 4 +down 2 +forward 4 +forward 9 +forward 1 +forward 7 +down 3 +down 4 +up 9 +down 6 +forward 9 +down 4 +down 2 +down 5 +down 3 +forward 2 +forward 9 +forward 3 +down 5 +up 1 +down 9 +forward 9 +down 7 +forward 6 +down 6 +down 9 +down 7 +down 8 +down 2 +up 3 +forward 6 +forward 3 +up 4 +down 6 +down 8 +down 2 +down 1 +up 9 +down 1 +down 8 +forward 5 +forward 4 +forward 9 +forward 3 +forward 9 +down 5 +up 9 +down 6 +forward 4 +down 6 +forward 4 +forward 9 +down 7 +up 9 +up 2 +forward 5 +forward 6 +up 2 +forward 8 +down 6 +forward 8 +forward 1 +forward 2 +forward 6 +down 3 +up 2 +forward 7 +up 8 +forward 2 +forward 5 +forward 4 +up 6 +forward 9 +up 8 +down 3 +up 7 +up 2 +down 2 +up 4 +up 5 +forward 5 +down 9 +forward 2 +down 1 +down 6 +down 4 +down 1 +down 1 +forward 4 +forward 7 +down 4 +down 2 +forward 7 +down 4 +up 1 +up 8 +down 6 +down 8 +forward 6 +down 8 +up 2 +down 7 +forward 5 +forward 8 +down 9 +forward 1 +up 7 +down 5 +up 1 +up 6 +down 3 +down 4 +down 9 +down 6 +forward 1 +down 1 +forward 4 +down 4 +down 8 +up 1 +down 7 +forward 1 +down 6 +down 4 +down 5 +forward 6 +forward 8 +down 5 +down 5 +up 3 +forward 8 +down 4 +down 3 +up 1 +up 8 +forward 1 +down 6 +down 2 +down 6 +down 1 +forward 9 +down 1 +forward 6 +forward 9 +down 5 +up 4 +down 5 +down 1 +forward 2 +down 2 +forward 9 +down 3 +forward 7 +forward 8 +forward 5 +down 7 +down 6 +down 8 +forward 7 +up 7 +forward 6 +forward 3 +down 2 +forward 9 +forward 4 +down 6 +down 6 +up 9 +down 1 +forward 5 +forward 2 +forward 2 +forward 2 +down 8 +up 1 +down 4 +forward 3 +down 3 +up 4 +down 6 +forward 2 +forward 8 +forward 9 +forward 3 +down 4 +forward 2 +forward 5 +down 5 +up 8 +up 9 +up 3 +forward 9 +forward 3 +forward 3 +forward 8 +forward 2 +forward 7 +down 8 +down 6 +forward 6 +forward 8 +down 1 +forward 3 +down 7 +forward 5 +forward 3 +forward 3 +down 3 +down 5 +down 2 +down 6 +up 2 +up 7 +down 9 +forward 6 +down 9 +down 8 +up 8 +down 1 +forward 9 +down 8 +forward 7 +forward 6 +down 5 +down 7 +down 4 +forward 7 +down 8 +down 9 +down 4 +up 8 +forward 2 +up 6 +forward 6 +forward 3 +forward 6 +up 9 +forward 1 +down 3 +up 6 +down 8 +up 4 +up 5 +forward 8 +forward 5 +forward 3 +forward 3 +forward 4 +down 4 +forward 2 +up 2 +down 7 +down 5 +forward 7 +down 8 +forward 3 +up 5 +down 4 +down 1 +down 5 +forward 6 +forward 8 +forward 6 +down 2 +down 7 +forward 6 +forward 2 +forward 7 +down 5 +forward 2 +forward 7 +down 9 +down 9 +down 4 +down 7 +down 3 +forward 1 +up 8 +down 7 +forward 2 +forward 4 +up 2 +forward 2 +down 2 +up 2 +up 9 +forward 1 +down 5 +down 1 +forward 8 +up 3 +up 4 +down 3 +up 2 +down 8 +down 6 +down 4 +up 7 +forward 4 +down 7 +down 4 +up 3 +up 8 +down 1 +down 7 +forward 1 +down 2 +forward 6 +down 9 +forward 3 +down 9 +up 5 +up 1 +down 4 +forward 1 +down 4 +forward 4 +up 4 +forward 7 +down 9 +down 2 +down 8 +forward 2 +up 3 +forward 2 +down 7 +forward 8 +forward 6 +forward 1 +up 9 +forward 7 +up 4 +down 4 +down 3 +down 7 +forward 5 +forward 3 +forward 7 diff --git a/Advent-of-Code-2021/AOC-2/input-2.txt~ b/Advent-of-Code-2021/AOC-2/input-2.txt~ new file mode 100644 index 0000000..e69de29 -- cgit v1.2.3