From 9f7b0cd76272068588d0a7220408f91390c5b583 Mon Sep 17 00:00:00 2001 From: jacopograndi Date: Thu, 6 Jan 2022 18:42:22 +0100 Subject: moved --- 2021/day05/day05.cpp | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 2021/day05/day05.cpp (limited to '2021/day05/day05.cpp') diff --git a/2021/day05/day05.cpp b/2021/day05/day05.cpp new file mode 100644 index 0000000..895dba0 --- /dev/null +++ b/2021/day05/day05.cpp @@ -0,0 +1,100 @@ +#include +#include +#include +#include +#include + +#include "../utils.h" + +class Line { + public: + Line (int a, int b, int c, int d) : a(a), b(b), c(c), d(d) { } + Line (std::string line) { + std::vector parts, start, end; + split(parts, line, "->"); + split(start, parts[0], ","); + split(end, parts[1], ","); + a = std::stoi(start[0]); + b = std::stoi(start[1]); + c = std::stoi(end[0]); + d = std::stoi(end[1]); + if (c-a == 0) xdir = 0; + else { xdir = (c-a) > 0 ? 1 : -1; } + if (d-b == 0) ydir = 0; + else { ydir = (d-b) > 0 ? 1 : -1; } + } + int a, b, c, d, xdir, ydir; + + int length () { return abs(a-c) + abs(b-d); } + + bool operator==(Line& oth) { + return a == oth.a && b == oth.b && c == oth.c && d == oth.d; + } +}; + +int main (int argc, char *argv[]) { + std::string raw; + std::getline(std::ifstream(argv[1]), raw, '\0'); + + std::vector lines; + std::vector strlines; + split(strlines, raw, "\n"); + for (auto strline : strlines) { + if (strline.size() == 0) continue; + Line line { strline }; + if (line.xdir != 0 && line.ydir != 0 + && std::stoi(argv[2]) == 0) continue; + lines.push_back(line); + } + + int intersections = 0; + std::map, int> overlaps; + for (auto& line : lines) { + int dist = 0; + bool straight = true; + if (line.xdir != 0 && line.ydir != 0) straight = false; + for (int i=0; dist 9) amt = 9; + if (amt > 0) std::cout << amt; + else std::cout << "."; + + } + std::cout << std::endl; + } + */ + + std::cout << "intersections: " << intersections << std::endl; + + return 0; +} -- cgit v1.2.3-54-g00ecf