diff --git a/2019/inputs/10.txt b/2019/inputs/10.txt new file mode 100644 index 0000000..3d1b1f7 --- /dev/null +++ b/2019/inputs/10.txt @@ -0,0 +1,30 @@ +.#.####..#.#...#...##..#.#.##. +..#####.##..#..##....#..#...#. +......#.......##.##.#....##..# +..#..##..#.###.....#.#..###.#. +..#..#..##..#.#.##..###....... +...##....#.##.#.#..##.##.#...# +.##...#.#.##..#.#........#.#.. +.##...##.##..#.#.##.#.#.#.##.# +#..##....#...###.#..##.#...##. +.###.###..##......#..#...###.# +.#..#.####.#..#....#.##..#.#.# +..#...#..#.#######....###..... +####..#.#.#...##...##....#..## +##..#.##.#.#..##.###.#.##.##.. +..#.........#.#.#.#.......#..# +...##.#.....#.#.##........#..# +##..###.....#.............#.## +.#...#....#..####.#.#......##. +..#..##..###...#.....#...##..# +...####..#.#.##..#....#.#..... +####.#####.#.#....#.#....##.#. +#.#..#......#.........##..#.#. +#....##.....#........#..##.##. +.###.##...##..#.##.#.#...#.#.# +##.###....##....#.#.....#.###. +..#...#......#........####..#. +#....#.###.##.#...#.#.#.#..... +.........##....#...#.....#..## +###....#.........#..#..#.#.#.. +##...#...###.#..#.###....#.##. diff --git a/2019/src/day10.cpp b/2019/src/day10.cpp index 391e112..1b76f1e 100644 --- a/2019/src/day10.cpp +++ b/2019/src/day10.cpp @@ -1,8 +1,55 @@ #include +#include +#include #include "days.hpp" +#include "point.hpp" + +namespace { + typedef aoc2019::Point point_t; + + std::vector read_points(std::istream& input) { + std::vector result; + + int y = 0; + + for (std::string buffer; std::getline(input, buffer); ++y) { + std::size_t x = 0; + + while ((x = buffer.find('#', x)) != std::string::npos) { + result.push_back({(int) x, y}); + x += 1; + } + } + + return result; + } + + point_t simplify(point_t x) { + auto gcd = std::abs(std::gcd(x[0], x[1])); + if (gcd > 1) { + return { x[0] / gcd, x[1] / gcd }; + } + + return x; + } +} void aoc2019::day10_part1(std::istream &input, std::ostream &output) { - output << "Not implemented\n"; + const auto points = read_points(input); + std::size_t best = 0; + + for (auto point : points) { + std::unordered_set visible; + + for (auto asteroid : points) { + if (asteroid == point) continue; + visible.insert(simplify(asteroid - point)); + } + + best = std::max(visible.size(), best); + } + + output << best << std::endl; } void aoc2019::day10_part2(std::istream &input, std::ostream &output) {