From 48966f12832ac97228132e56fb3159099f3e466e Mon Sep 17 00:00:00 2001 From: kartofen Date: Sun, 31 Jul 2022 11:55:45 +0300 Subject: cleanup --- Advent-of-Code-2021/AOC-2/aoc-2 | Bin 16568 -> 0 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~ | 0 Advent-of-Code-2021/AOC-2/main.c | 104 +++++++++++++++++++++++++++++++++ 5 files changed, 104 insertions(+), 104 deletions(-) delete mode 100755 Advent-of-Code-2021/AOC-2/aoc-2 delete mode 100644 Advent-of-Code-2021/AOC-2/aoc-2.c delete mode 100644 Advent-of-Code-2021/AOC-2/aoc-2.c~ delete mode 100644 Advent-of-Code-2021/AOC-2/input-2.txt~ create mode 100644 Advent-of-Code-2021/AOC-2/main.c (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 deleted file mode 100755 index c15492c..0000000 Binary files a/Advent-of-Code-2021/AOC-2/aoc-2 and /dev/null differ diff --git a/Advent-of-Code-2021/AOC-2/aoc-2.c b/Advent-of-Code-2021/AOC-2/aoc-2.c deleted file mode 100644 index 6c212b1..0000000 --- a/Advent-of-Code-2021/AOC-2/aoc-2.c +++ /dev/null @@ -1,104 +0,0 @@ -#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~ deleted file mode 100644 index e69de29..0000000 diff --git a/Advent-of-Code-2021/AOC-2/input-2.txt~ b/Advent-of-Code-2021/AOC-2/input-2.txt~ deleted file mode 100644 index e69de29..0000000 diff --git a/Advent-of-Code-2021/AOC-2/main.c b/Advent-of-Code-2021/AOC-2/main.c new file mode 100644 index 0000000..6c212b1 --- /dev/null +++ b/Advent-of-Code-2021/AOC-2/main.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; +} -- cgit v1.2.3