From 69de9551581f237a3d6f7287895022fe661e0bb7 Mon Sep 17 00:00:00 2001 From: Bert Peters Date: Sat, 23 Jan 2021 15:00:04 +0100 Subject: [PATCH] Remove C++ solutions --- 2019/.gitignore | 1 - 2019/README.md | 31 ----- 2019/src/day01.cpp | 26 ---- 2019/src/day02.cpp | 36 ------ 2019/src/day03.cpp | 84 ------------- 2019/src/day04.cpp | 94 -------------- 2019/src/day05.cpp | 15 --- 2019/src/day06.cpp | 68 ---------- 2019/src/day07.cpp | 69 ----------- 2019/src/day08.cpp | 69 ----------- 2019/src/day09.cpp | 33 ----- 2019/src/day10.cpp | 118 ------------------ 2019/src/day11.cpp | 80 ------------ 2019/src/day12.cpp | 100 --------------- 2019/src/day13.cpp | 138 --------------------- 2019/src/day14.cpp | 146 ---------------------- 2019/src/day15.cpp | 153 ----------------------- 2019/src/day16.cpp | 117 ------------------ 2019/src/day17.cpp | 103 ---------------- 2019/src/day17/route-map.py | 76 ------------ 2019/src/day18.cpp | 226 ---------------------------------- 2019/src/day19.cpp | 89 ------------- 2019/src/day20.cpp | 215 -------------------------------- 2019/src/day21.cpp | 47 ------- 2019/src/day22.cpp | 149 ---------------------- 2019/src/day23.cpp | 10 -- 2019/src/day24.cpp | 188 ---------------------------- 2019/src/day25.cpp | 10 -- 2019/src/days.hpp | 57 --------- 2019/src/implementations.cpp | 35 ------ 2019/src/implementations.hpp | 9 -- 2019/src/point.hpp | 78 ------------ 2019/src/runner.cpp | 135 -------------------- 2019/src/utils.cpp | 191 ---------------------------- 2019/src/utils.hpp | 123 ------------------ 2019/tests/samples/.gitkeep | 1 - 2019/tests/samples/01-1-1.in | 1 - 2019/tests/samples/01-1-1.out | 1 - 2019/tests/samples/03-1-1.in | 2 - 2019/tests/samples/03-1-1.out | 1 - 2019/tests/samples/03-1-2.in | 2 - 2019/tests/samples/03-1-2.out | 1 - 2019/tests/samples/03-1-3.in | 2 - 2019/tests/samples/03-1-3.out | 1 - 2019/tests/samples/03-2-1.in | 1 - 2019/tests/samples/03-2-1.out | 1 - 2019/tests/samples/03-2-2.in | 1 - 2019/tests/samples/03-2-2.out | 1 - 2019/tests/samples/03-2-3.in | 1 - 2019/tests/samples/03-2-3.out | 1 - 2019/tests/samples/06-1-1.in | 11 -- 2019/tests/samples/06-1-1.out | 1 - 2019/tests/samples/06-2-1.in | 13 -- 2019/tests/samples/06-2-1.out | 1 - 2019/tests/samples/07-1-1.in | 1 - 2019/tests/samples/07-1-1.out | 1 - 2019/tests/samples/07-1-2.in | 2 - 2019/tests/samples/07-1-2.out | 1 - 2019/tests/samples/07-1-3.in | 2 - 2019/tests/samples/07-1-3.out | 1 - 2019/tests/samples/07-2-1.in | 2 - 2019/tests/samples/07-2-1.out | 1 - 2019/tests/samples/07-2-2.in | 3 - 2019/tests/samples/07-2-2.out | 1 - 2019/tests/samples/10-1-1.in | 5 - 2019/tests/samples/10-1-1.out | 1 - 2019/tests/samples/10-1-2.in | 10 -- 2019/tests/samples/10-1-2.out | 1 - 2019/tests/samples/10-1-3.in | 10 -- 2019/tests/samples/10-1-3.out | 1 - 2019/tests/samples/10-1-4.in | 10 -- 2019/tests/samples/10-1-4.out | 1 - 2019/tests/samples/10-1-5.in | 20 --- 2019/tests/samples/10-1-5.out | 1 - 2019/tests/samples/12-2-1.in | 4 - 2019/tests/samples/12-2-1.out | 1 - 2019/tests/samples/12-2-2.in | 4 - 2019/tests/samples/12-2-2.out | 1 - 2019/tests/samples/14-1-1.in | 6 - 2019/tests/samples/14-1-1.out | 1 - 2019/tests/samples/14-1-2.in | 7 -- 2019/tests/samples/14-1-2.out | 1 - 2019/tests/samples/14-1-3.in | 9 -- 2019/tests/samples/14-1-3.out | 1 - 2019/tests/samples/14-1-4.in | 12 -- 2019/tests/samples/14-1-4.out | 1 - 2019/tests/samples/14-1-5.in | 17 --- 2019/tests/samples/14-1-5.out | 1 - 2019/tests/samples/14-2-1.in | 1 - 2019/tests/samples/14-2-1.out | 1 - 2019/tests/samples/14-2-2.in | 1 - 2019/tests/samples/14-2-2.out | 1 - 2019/tests/samples/14-2-3.in | 1 - 2019/tests/samples/14-2-3.out | 1 - 2019/tests/samples/16-1-1.in | 1 - 2019/tests/samples/16-1-1.out | 1 - 2019/tests/samples/16-1-2.in | 1 - 2019/tests/samples/16-1-2.out | 1 - 2019/tests/samples/16-1-3.in | 1 - 2019/tests/samples/16-1-3.out | 1 - 2019/tests/samples/18-1-1.in | 3 - 2019/tests/samples/18-1-1.out | 1 - 2019/tests/samples/18-1-2.in | 5 - 2019/tests/samples/18-1-2.out | 1 - 2019/tests/samples/18-1-3.in | 5 - 2019/tests/samples/18-1-3.out | 1 - 2019/tests/samples/18-1-4.in | 9 -- 2019/tests/samples/18-1-4.out | 1 - 2019/tests/samples/18-1-5.in | 6 - 2019/tests/samples/18-1-5.out | 1 - 2019/tests/samples/18-2-1.in | 7 -- 2019/tests/samples/18-2-1.out | 1 - 2019/tests/samples/20-1-1.in | 19 --- 2019/tests/samples/20-1-1.out | 1 - 2019/tests/samples/20-1-2.in | 37 ------ 2019/tests/samples/20-1-2.out | 1 - 2019/tests/samples/20-2-2.in | 37 ------ 2019/tests/samples/20-2-2.out | 1 - 2019/tests/samples/24-1-1.in | 5 - 2019/tests/samples/24-1-1.out | 1 - 2019/tests/test_intcode.cpp | 78 ------------ 2019/tests/test_solutions.cpp | 110 ----------------- 122 files changed, 3647 deletions(-) delete mode 100644 2019/README.md delete mode 100644 2019/src/day01.cpp delete mode 100644 2019/src/day02.cpp delete mode 100644 2019/src/day03.cpp delete mode 100644 2019/src/day04.cpp delete mode 100644 2019/src/day05.cpp delete mode 100644 2019/src/day06.cpp delete mode 100644 2019/src/day07.cpp delete mode 100644 2019/src/day08.cpp delete mode 100644 2019/src/day09.cpp delete mode 100644 2019/src/day10.cpp delete mode 100644 2019/src/day11.cpp delete mode 100644 2019/src/day12.cpp delete mode 100644 2019/src/day13.cpp delete mode 100644 2019/src/day14.cpp delete mode 100644 2019/src/day15.cpp delete mode 100644 2019/src/day16.cpp delete mode 100644 2019/src/day17.cpp delete mode 100644 2019/src/day17/route-map.py delete mode 100644 2019/src/day18.cpp delete mode 100644 2019/src/day19.cpp delete mode 100644 2019/src/day20.cpp delete mode 100644 2019/src/day21.cpp delete mode 100644 2019/src/day22.cpp delete mode 100644 2019/src/day23.cpp delete mode 100644 2019/src/day24.cpp delete mode 100644 2019/src/day25.cpp delete mode 100644 2019/src/days.hpp delete mode 100644 2019/src/implementations.cpp delete mode 100644 2019/src/implementations.hpp delete mode 100644 2019/src/point.hpp delete mode 100644 2019/src/runner.cpp delete mode 100644 2019/src/utils.cpp delete mode 100644 2019/src/utils.hpp delete mode 100644 2019/tests/samples/.gitkeep delete mode 100644 2019/tests/samples/01-1-1.in delete mode 100644 2019/tests/samples/01-1-1.out delete mode 100644 2019/tests/samples/03-1-1.in delete mode 100644 2019/tests/samples/03-1-1.out delete mode 100644 2019/tests/samples/03-1-2.in delete mode 100644 2019/tests/samples/03-1-2.out delete mode 100644 2019/tests/samples/03-1-3.in delete mode 100644 2019/tests/samples/03-1-3.out delete mode 120000 2019/tests/samples/03-2-1.in delete mode 100644 2019/tests/samples/03-2-1.out delete mode 120000 2019/tests/samples/03-2-2.in delete mode 100644 2019/tests/samples/03-2-2.out delete mode 120000 2019/tests/samples/03-2-3.in delete mode 100644 2019/tests/samples/03-2-3.out delete mode 100644 2019/tests/samples/06-1-1.in delete mode 100644 2019/tests/samples/06-1-1.out delete mode 100644 2019/tests/samples/06-2-1.in delete mode 100644 2019/tests/samples/06-2-1.out delete mode 100644 2019/tests/samples/07-1-1.in delete mode 100644 2019/tests/samples/07-1-1.out delete mode 100644 2019/tests/samples/07-1-2.in delete mode 100644 2019/tests/samples/07-1-2.out delete mode 100644 2019/tests/samples/07-1-3.in delete mode 100644 2019/tests/samples/07-1-3.out delete mode 100644 2019/tests/samples/07-2-1.in delete mode 100644 2019/tests/samples/07-2-1.out delete mode 100644 2019/tests/samples/07-2-2.in delete mode 100644 2019/tests/samples/07-2-2.out delete mode 100644 2019/tests/samples/10-1-1.in delete mode 100644 2019/tests/samples/10-1-1.out delete mode 100644 2019/tests/samples/10-1-2.in delete mode 100644 2019/tests/samples/10-1-2.out delete mode 100644 2019/tests/samples/10-1-3.in delete mode 100644 2019/tests/samples/10-1-3.out delete mode 100644 2019/tests/samples/10-1-4.in delete mode 100644 2019/tests/samples/10-1-4.out delete mode 100644 2019/tests/samples/10-1-5.in delete mode 100644 2019/tests/samples/10-1-5.out delete mode 100644 2019/tests/samples/12-2-1.in delete mode 100644 2019/tests/samples/12-2-1.out delete mode 100644 2019/tests/samples/12-2-2.in delete mode 100644 2019/tests/samples/12-2-2.out delete mode 100644 2019/tests/samples/14-1-1.in delete mode 100644 2019/tests/samples/14-1-1.out delete mode 100644 2019/tests/samples/14-1-2.in delete mode 100644 2019/tests/samples/14-1-2.out delete mode 100644 2019/tests/samples/14-1-3.in delete mode 100644 2019/tests/samples/14-1-3.out delete mode 100644 2019/tests/samples/14-1-4.in delete mode 100644 2019/tests/samples/14-1-4.out delete mode 100644 2019/tests/samples/14-1-5.in delete mode 100644 2019/tests/samples/14-1-5.out delete mode 120000 2019/tests/samples/14-2-1.in delete mode 100644 2019/tests/samples/14-2-1.out delete mode 120000 2019/tests/samples/14-2-2.in delete mode 100644 2019/tests/samples/14-2-2.out delete mode 120000 2019/tests/samples/14-2-3.in delete mode 100644 2019/tests/samples/14-2-3.out delete mode 100644 2019/tests/samples/16-1-1.in delete mode 100644 2019/tests/samples/16-1-1.out delete mode 100644 2019/tests/samples/16-1-2.in delete mode 100644 2019/tests/samples/16-1-2.out delete mode 100644 2019/tests/samples/16-1-3.in delete mode 100644 2019/tests/samples/16-1-3.out delete mode 100644 2019/tests/samples/18-1-1.in delete mode 100644 2019/tests/samples/18-1-1.out delete mode 100644 2019/tests/samples/18-1-2.in delete mode 100644 2019/tests/samples/18-1-2.out delete mode 100644 2019/tests/samples/18-1-3.in delete mode 100644 2019/tests/samples/18-1-3.out delete mode 100644 2019/tests/samples/18-1-4.in delete mode 100644 2019/tests/samples/18-1-4.out delete mode 100644 2019/tests/samples/18-1-5.in delete mode 100644 2019/tests/samples/18-1-5.out delete mode 100644 2019/tests/samples/18-2-1.in delete mode 100644 2019/tests/samples/18-2-1.out delete mode 100644 2019/tests/samples/20-1-1.in delete mode 100644 2019/tests/samples/20-1-1.out delete mode 100644 2019/tests/samples/20-1-2.in delete mode 100644 2019/tests/samples/20-1-2.out delete mode 100644 2019/tests/samples/20-2-2.in delete mode 100644 2019/tests/samples/20-2-2.out delete mode 100644 2019/tests/samples/24-1-1.in delete mode 100644 2019/tests/samples/24-1-1.out delete mode 100644 2019/tests/test_intcode.cpp delete mode 100644 2019/tests/test_solutions.cpp diff --git a/2019/.gitignore b/2019/.gitignore index 8eee68f..e69de29 100644 --- a/2019/.gitignore +++ b/2019/.gitignore @@ -1 +0,0 @@ -cmake-build-* diff --git a/2019/README.md b/2019/README.md deleted file mode 100644 index f857611..0000000 --- a/2019/README.md +++ /dev/null @@ -1,31 +0,0 @@ -# Advent of Code 2019 - -This project contains my implementations for Advent of Code 2019. The -goal is to create reasonably fast C++ implementations in readable and -ergonomic C++. At the end of the contest, I will probably do a write- -up of some sorts. - - -## How to compile - -Install the dependencies: - -- [GTest](https://github.com/google/googletest) **Note:** this project - by default tries to dynamically link GTest, and the Ubuntu packages - only provide a statically linked archive. You may need to compile it - for yourself. - -``` -mkdir build && cd build -cmake .. -make -``` - -You can then use the generated executable `runner`. - -## Running tests - -Tests can be executed with `make test`. The `tests` folder contains a -`samples` folder. This folder contains pairs of `XX-Y-something.in` and -`XX-Y-something.out`, which will be taken as the expected input and -output of the implementations. You can add your own samples to this mix. diff --git a/2019/src/day01.cpp b/2019/src/day01.cpp deleted file mode 100644 index 457d8a8..0000000 --- a/2019/src/day01.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include -#include "days.hpp" - -static inline int required(int weight) { - return weight / 3 - 2; -} - -void aoc2019::day01_part1(std::istream &input, std::ostream &output) { - int total = 0; - for (int current; input >> current;) { - total += required(current); - } - - output << total << std::endl; -} - -void aoc2019::day01_part2(std::istream &input, std::ostream &output) { - int total = 0; - for (int current; input >> current;) { - for (int fuel = required(current); fuel > 0; fuel = required(fuel)) { - total += fuel; - } - } - - output << total << std::endl; -} diff --git a/2019/src/day02.cpp b/2019/src/day02.cpp deleted file mode 100644 index d251264..0000000 --- a/2019/src/day02.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include -#include -#include -#include -#include "days.hpp" -#include "utils.hpp" - -static int run_program(std::vector program) { - aoc2019::IntCodeComputer computer(std::move(program)); - computer.run(); - - return computer[0]; -} - -void aoc2019::day02_part1(std::istream &input, std::ostream &output) { - auto program = IntCodeComputer::read_intcode(input); - program[1] = 12; - program[2] = 2; - output << run_program(std::move(program)) << std::endl; -} - -void aoc2019::day02_part2(std::istream &input, std::ostream &output) { - auto program = IntCodeComputer::read_intcode(input); - - for (int noun = 0; noun < 100; ++noun) { - for (int verb = 0; verb < 100; ++verb) { - program[1] = noun; - program[2] = verb; - if (run_program(program) == 19690720) { - output << 100 * noun + verb << std::endl; - return; - } - } - } - throw std::domain_error("No valid solution."); -} diff --git a/2019/src/day03.cpp b/2019/src/day03.cpp deleted file mode 100644 index f618c7a..0000000 --- a/2019/src/day03.cpp +++ /dev/null @@ -1,84 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include "days.hpp" -#include "point.hpp" -#include "utils.hpp" - -namespace { - typedef aoc2019::Point point_t; - - const std::unordered_map DIRECTION_MAP = { - {'U', {0, -1}}, - {'D', {0, 1}}, - {'L', {-1, 0}}, - {'R', {1, 0}}, - }; - - std::unordered_map get_points(std::string_view line) { - std::unordered_map points{}; - point_t pos = {}; - - int steps = 0; - for (auto entry = aoc2019::strtok(line); !line.empty() || !entry.empty(); entry = aoc2019::strtok(line)) { - const auto dir = DIRECTION_MAP.at(entry[0]); - std::size_t amount = 0; - aoc2019::from_chars(entry.substr(1), amount); - assert(amount > 0 && "Must have some valid direction"); - - for (std::size_t i = 0; i < amount; ++i) { - ++steps; - pos += dir; - if (!points.count(pos)) { - points[pos] = steps; - } - } - } - - return points; - } - - std::pair, std::unordered_map> read_input(std::istream& input) { - std::string buffer; - std::getline(input, buffer); - auto a = get_points(buffer); - std::getline(input, buffer); - auto b = get_points(buffer); - - return { std::move(a), std::move(b) }; - } -} - -void aoc2019::day03_part1(std::istream &input, std::ostream &output) { - auto [a, b] = read_input(input); - - int best = std::numeric_limits::max(); - - for (const auto& point : a) { - if (b.count(point.first) && point.first.l1() < best) { - best = point.first.l1(); - } - } - - output << best << std::endl; -} - -void aoc2019::day03_part2(std::istream &input, std::ostream &output) { - auto [a, b] = read_input(input); - - int best = std::numeric_limits::max(); - - for (const auto& ap : a) { - const auto bp = b.find(ap.first); - - if (bp != b.cend() && (ap.second + bp->second) < best) { - best = ap.second + bp->second; - } - } - - output << best << std::endl; -} diff --git a/2019/src/day04.cpp b/2019/src/day04.cpp deleted file mode 100644 index a8dd0b2..0000000 --- a/2019/src/day04.cpp +++ /dev/null @@ -1,94 +0,0 @@ -#include -#include -#include "days.hpp" - -namespace { - constexpr bool is_valid_pass(int num) { - bool has_double = false; - int prev = 11; - - for (; num != 0; num /= 10) { - int digit = num % 10; - - if (digit == prev) { - has_double = true; - } - - if (digit > prev) { - return false; - } - - prev = digit; - } - - return has_double; - } - - constexpr bool is_valid_pass2(int num) { - int prev = 11; - bool has_double = false; - int run = 1; - - for (; num != 0; num /= 10) { - int digit = num % 10; - - if (digit == prev) { - ++run; - } else { - if (run == 2) { - has_double = true; - } - run = 1; - } - - if (digit > prev) { - return false; - } - - prev = digit; - } - - return has_double || run == 2; - } - - std::pair read_input(std::istream& input) { - int a, b; - input >> a; - input.ignore(); - input >> b; - - return {a, b}; - } -} - -void aoc2019::day04_part1(std::istream &input, std::ostream &output) { - auto [start_range, end_range] = read_input(input); - - int num_valid = 0; - for (; start_range <= end_range; ++start_range) { - num_valid += is_valid_pass(start_range); - } - - output << num_valid << std::endl; -} - -void aoc2019::day04_part2(std::istream &input, std::ostream &output) { - auto [start_range, end_range] = read_input(input); - - int num_valid = 0; - for (; start_range <= end_range; ++start_range) { - num_valid += is_valid_pass2(start_range); - } - - output << num_valid << std::endl; -} - -// Poor man's unit tests -static_assert(is_valid_pass(122345)); -static_assert(is_valid_pass(111111)); -static_assert(!is_valid_pass(223450)); -static_assert(!is_valid_pass(123678)); - -static_assert(is_valid_pass2(112233)); -static_assert(!is_valid_pass2(123444)); -static_assert(is_valid_pass2(111122)); diff --git a/2019/src/day05.cpp b/2019/src/day05.cpp deleted file mode 100644 index aaa749d..0000000 --- a/2019/src/day05.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include "days.hpp" -#include "utils.hpp" - -void aoc2019::day05_part1(std::istream &input, std::ostream &output) { - auto program = IntCodeComputer::read_intcode(input); - auto result = run_intcode(program, { 1 }); - output << result.back() << std::endl; -} - -void aoc2019::day05_part2(std::istream &input, std::ostream &output) { - auto program = IntCodeComputer::read_intcode(input); - auto result = run_intcode(program, { 5 }); - output << result.back() << std::endl; -} diff --git a/2019/src/day06.cpp b/2019/src/day06.cpp deleted file mode 100644 index 8ea162a..0000000 --- a/2019/src/day06.cpp +++ /dev/null @@ -1,68 +0,0 @@ -#include -#include -#include -#include -#include "days.hpp" - -namespace { - std::vector> read_orbits(std::istream &input) { - std::vector> result; - std::string name1, name2; - - while (std::getline(input, name1, ')')) { - std::getline(input, name2); - - result.emplace_back(name1, name2); - } - - return result; - } -} - -void aoc2019::day06_part1(std::istream &input, std::ostream &output) { - std::unordered_map> orbits; - - for (auto[a, b] : read_orbits(input)) { - orbits[std::move(a)].emplace_back(std::move(b)); - } - - std::deque> todo = {{"COM", 0}}; - int total_orbits = 0; - - while (!todo.empty()) { - auto[name, offset] = todo.front(); - todo.pop_front(); - - total_orbits += offset; - - for (const auto& partner : orbits[name]) { - todo.emplace_back(partner, offset + 1); - } - } - - output << total_orbits << std::endl; -} - -void aoc2019::day06_part2(std::istream &input, std::ostream &output) { - std::unordered_map ancestors; - - for (auto[a, b] : read_orbits(input)) { - ancestors[std::move(b)] = std::move(a); - } - - std::unordered_map santa_ancestors; - - for (auto current = ancestors["SAN"]; current != "COM"; current = ancestors[current]) { - santa_ancestors[ancestors[current]] = santa_ancestors[current] + 1; - } - - int dist = 0; - for (auto current = ancestors["YOU"]; current != "COM"; current = ancestors[current], ++dist) { - if (auto it = santa_ancestors.find(current); it != santa_ancestors.end()) { - output << dist + it->second << std::endl; - return; - } - } - - throw std::domain_error("No valid path."); -} diff --git a/2019/src/day07.cpp b/2019/src/day07.cpp deleted file mode 100644 index cc57b1e..0000000 --- a/2019/src/day07.cpp +++ /dev/null @@ -1,69 +0,0 @@ -#include -#include -#include -#include "days.hpp" -#include "utils.hpp" - -namespace { - using aoc2019::IntCodeComputer; - - std::int64_t simulate(const std::vector &program, const std::array &phases) { - std::int64_t state = 0; - for (auto phase : phases) { - std::deque outputs; - IntCodeComputer computer{program, {phase, state}}; - computer.connectOutput(outputs); - computer.run(); - state = outputs.front(); - } - - return state; - } - - int simulate2(const std::vector &program, const std::array &phases) { - std::vector computers; - for (int phase : phases) { - computers.emplace_back(program, std::deque{phase}); - } - - for (int i = 0; i < computers.size(); ++i) { - computers[i].connectOutput(computers[(i + 1) % 5]); - } - - computers[0].sendInput(0); - - while (std::any_of(computers.begin(), computers.end(), [](const auto &c) { return !c.isTerminated();})) { - for (auto& computer : computers) { - computer.run(); - } - } - - return computers[0].currentInputs().back(); - } -} - -void aoc2019::day07_part1(std::istream &input, std::ostream &output) { - const auto program = aoc2019::IntCodeComputer::read_intcode(input); - std::array phases{0, 1, 2, 3, 4}; - - std::int64_t best = 0; - - do { - best = std::max(simulate(program, phases), best); - } while (std::next_permutation(phases.begin(), phases.end())); - - output << best << std::endl; -} - -void aoc2019::day07_part2(std::istream &input, std::ostream &output) { - const auto program = aoc2019::IntCodeComputer::read_intcode(input); - std::array phases{5, 6, 7, 8, 9}; - - int best = 0; - - do { - best = std::max(simulate2(program, phases), best); - } while (std::next_permutation(phases.begin(), phases.end())); - - output << best << std::endl; -} diff --git a/2019/src/day08.cpp b/2019/src/day08.cpp deleted file mode 100644 index 4c6c0e0..0000000 --- a/2019/src/day08.cpp +++ /dev/null @@ -1,69 +0,0 @@ -#include -#include -#include -#include -#include -#include "days.hpp" - -namespace { - constexpr std::size_t WIDTH = 25; - constexpr std::size_t HEIGHT = 6; - constexpr std::size_t TILE_SIZE = WIDTH * HEIGHT; - - enum Color { - BLACK = '0', - WHITE = '1', - TRANSPARENT = '2', - }; -} - - -void aoc2019::day08_part1(std::istream &input, std::ostream &output) { - std::string buffer; - std::getline(input, buffer); - - std::string_view image = buffer; - auto best = std::numeric_limits::max(); - auto best_score = 0; - - for (std::size_t i = 0; i < buffer.length(); i += TILE_SIZE) { - auto tile = image.substr(i, TILE_SIZE); - - auto zeros = std::count(tile.begin(), tile.end(), '0'); - - if (zeros < best) { - best = zeros; - - best_score = std::count(tile.begin(), tile.end(), '1') * std::count(tile.begin(), tile.end(), '2'); - } - } - - output << best_score << std::endl; -} - -void aoc2019::day08_part2(std::istream &input, std::ostream &output) { - std::string buffer; - std::getline(input, buffer); - - std::string_view image = buffer; - - std::array final_image; - std::fill(final_image.begin(), final_image.end(), TRANSPARENT); - - for (std::size_t i = 0; i < buffer.length(); i += TILE_SIZE) { - auto tile = image.substr(i, TILE_SIZE); - - for (int j = 0; j < TILE_SIZE; ++j) { - if (final_image[j] == TRANSPARENT) { - final_image[j] = static_cast(tile[j]); - } - } - } - - for (std::size_t i = 0; i < final_image.size(); ++i) { - output << (final_image[i] == WHITE ? '#' : ' '); - if (i % WIDTH == WIDTH - 1) { - output << '\n'; - } - } -} diff --git a/2019/src/day09.cpp b/2019/src/day09.cpp deleted file mode 100644 index d1721ad..0000000 --- a/2019/src/day09.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include -#include -#include "days.hpp" -#include "utils.hpp" - -void aoc2019::day09_part1(std::istream &input, std::ostream &output) { - std::deque outputs; - - IntCodeComputer computer(input, { 1 }); - computer.connectOutput(outputs); - - computer.run(); - - if (outputs.size() != 1) { - std::cerr << "Error: " << outputs.size() << std::endl; - for (auto c : outputs) { - std::cerr << c << std::endl; - } - } else { - output << outputs.front() << std::endl; - } -} - -void aoc2019::day09_part2(std::istream &input, std::ostream &output) { - std::deque outputs; - - IntCodeComputer computer(input, { 2 }); - computer.connectOutput(outputs); - - computer.run(); - - output << outputs.front() << std::endl; -} diff --git a/2019/src/day10.cpp b/2019/src/day10.cpp deleted file mode 100644 index f08a48d..0000000 --- a/2019/src/day10.cpp +++ /dev/null @@ -1,118 +0,0 @@ -#include -#include -#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; - } - - std::pair part1(const std::vector &points) { - std::size_t best = 0; - std::size_t best_index = 0; - std::unordered_set visible; - - for (std::size_t i = 0; i < points.size(); ++i) { - visible.clear(); - - const auto point = points[i]; - - for (auto asteroid : points) { - if (asteroid == point) continue; - visible.insert(simplify(asteroid - point)); - } - - if (visible.size() > best) { - best = visible.size(); - best_index = i; - } - - best = std::max(visible.size(), best); - } - - return {best, best_index}; - } -} - -void aoc2019::day10_part1(std::istream &input, std::ostream &output) { - const auto points = read_points(input); - - auto[best, _] = part1(points); - - output << best << std::endl; -} - -void aoc2019::day10_part2(std::istream &input, std::ostream &output) { - const auto points = read_points(input); - const auto[_, base] = part1(points); - const auto base_point = points[base]; - - std::unordered_map> angle_points; - - for (auto point : points) { - if (point == base_point) continue; - auto diff = point - base_point; - - angle_points[simplify(diff)].push_back(diff); - } - - std::vector> angles; - - for (auto &entry : angle_points) { - angles.emplace_back(std::atan2(entry.first[1], entry.first[0]), entry.first); - // Sort entries in descending order of distance so we can pop_back() them - std::sort(entry.second.begin(), entry.second.end(), [](auto a, auto b) { return a.l1() > b.l1(); }); - } - - std::sort(angles.begin(), angles.end(), std::greater<>{}); - - const auto starting_point = std::make_pair(float(0.5 * M_PI), - point_t{std::numeric_limits::max(), - std::numeric_limits::max()}); - - auto it = std::lower_bound(angles.begin(), angles.end(), starting_point, std::greater<>{}); - - for (int hits = 0; hits < 199; ++hits) { - angle_points[it->second].pop_back(); - - // Advance it to the next asteroid we can hit. - while (angle_points[it->second].empty()) { - ++it; - if (it == angles.end()) { - it = angles.begin(); - } - } - } - - auto final_asteroid = angle_points[it->second].back() + base_point; - - output << final_asteroid[0] * 100 + final_asteroid[1] << std::endl; -} diff --git a/2019/src/day11.cpp b/2019/src/day11.cpp deleted file mode 100644 index 21fb882..0000000 --- a/2019/src/day11.cpp +++ /dev/null @@ -1,80 +0,0 @@ -#include -#include -#include "days.hpp" -#include "utils.hpp" -#include "point.hpp" - -namespace { - typedef aoc2019::Point point_t; - using aoc2019::IntCodeComputer; - - inline point_t turn_right(point_t direction) { - return {-direction[1], direction[0]}; - } - - inline point_t turn_left(point_t direction) { - return {direction[1], -direction[0]}; - } - - std::unordered_map simulate(std::istream &input, bool background = false) { - std::unordered_map image; - - point_t direction{0, -1}; - point_t pos = {0, 0}; - - IntCodeComputer computer(IntCodeComputer::read_intcode(input), {}); - std::deque outputs; - - computer.connectOutput(outputs); - - while (!computer.isTerminated()) { - const auto it = image.find(pos); - computer.sendInput(it != image.end() ? it->second : background); - computer.run(); - - if (!outputs.empty()) { - assert(outputs.size() == 2); - auto color = outputs.front(); - auto turn = outputs.back(); - outputs.clear(); - - image[pos] = color; - - if (turn) { - direction = turn_right(direction); - } else { - direction = turn_left(direction); - } - - pos += direction; - } - } - - return image; - } -} - -void aoc2019::day11_part1(std::istream &input, std::ostream &output) { - const auto result = simulate(input); - - output << result.size() << std::endl; -} - -void aoc2019::day11_part2(std::istream &input, std::ostream &output) { - const auto result = simulate(input, true); - - // Determine bounding box - auto[lower,upper] = aoc2019::bounding_box(result); - - for (int y = lower[1]; y <= upper[1]; ++y) { - for (int x = lower[0]; x <= upper[0]; ++x) { - if (auto it = result.find({x, y}); it != result.end() && it->second) { - output << '#'; - } else { - output << ' '; - } - } - - output << '\n'; - } -} diff --git a/2019/src/day12.cpp b/2019/src/day12.cpp deleted file mode 100644 index f1340bf..0000000 --- a/2019/src/day12.cpp +++ /dev/null @@ -1,100 +0,0 @@ -#include -#include -#include -#include "days.hpp" -#include "point.hpp" - -namespace { - typedef aoc2019::Point point_t; - using aoc2019::from_chars; - - std::vector read_moons(std::istream &input) { - std::vector moons; - - point_t moon; - - while (aoc2019::read_line_numbers_and_garbage(input, moon.begin())) { - moons.push_back(moon); - } - - return moons; - } - - void update_velocity(const point_t &a, point_t &va, const point_t &b, point_t &vb) { - for (int i = 0; i < a.size(); ++i) { - if (a[i] < b[i]) { - va[i]++; - vb[i]--; - } else if (a[i] > b[i]) { - va[i]--; - vb[i]++; - } - } - } - - void update_velocities(const std::vector &positions, std::vector &velocities) { - for (int i = 0; i < positions.size(); ++i) { - for (int j = i + 1; j < positions.size(); ++j) { - update_velocity(positions[i], velocities[i], positions[j], velocities[j]); - } - } - } - - void simulate_step(std::vector &moons, std::vector &velocities) { - update_velocities(moons, velocities); - - for (int j = 0; j < moons.size(); ++j) { - moons[j] += velocities[j]; - } - } -} - -void aoc2019::day12_part1(std::istream &input, std::ostream &output) { - auto moons = read_moons(input); - std::vector velocities(moons.size()); - - for (int i = 0; i < 1000; ++i) { - simulate_step(moons, velocities); - } - - int energy = 0; - - for (int i = 0; i < moons.size(); ++i) { - energy += moons[i].l1() * velocities[i].l1(); - } - - output << energy << std::endl; -} - -void aoc2019::day12_part2(std::istream &input, std::ostream &output) { - const auto moons = read_moons(input); - auto moons_mut = moons; - std::vector velocities(moons.size()); - - std::array recurrence = {0, 0, 0}; - - std::uint64_t steps = 0; - - while (!std::all_of(recurrence.begin(), recurrence.end(), [](auto x) { return x > 0; })) { - simulate_step(moons_mut, velocities); - ++steps; - - for (int i = 0; i < 3; ++i) { - if (!recurrence[i]) { - bool back_again = - std::all_of(velocities.begin(), velocities.end(), [i](const auto &x) { return !x[i]; }) - && std::equal(moons_mut.begin(), moons_mut.end(), moons.begin(), - [i](const auto &a, const auto &b) { - return a[i] == b[i]; - }); - - if (back_again) { - recurrence[i] = steps; - } - } - } - } - - auto result = std::lcm(recurrence[0], std::lcm(recurrence[1], recurrence[2])); - output << result << std::endl; -} diff --git a/2019/src/day13.cpp b/2019/src/day13.cpp deleted file mode 100644 index f8625e6..0000000 --- a/2019/src/day13.cpp +++ /dev/null @@ -1,138 +0,0 @@ -#include -#ifdef ANIMATE_DAY13 -#include -#include -#endif -#include "days.hpp" -#include "utils.hpp" -#include "point.hpp" - -namespace { - typedef aoc2019::Point point_t; - - enum class Tile { - EMPTY, - WALL, - BLOCK, - PADDLE, - BALL, - }; - - typedef std::unordered_map Screen; - - std::optional update_screen(std::deque &output_buffer, Screen &screen) { - std::optional score; - while (!output_buffer.empty()) { - auto x = output_buffer.front(); output_buffer.pop_front(); - auto y = output_buffer.front(); output_buffer.pop_front(); - auto type = output_buffer.front(); output_buffer.pop_front(); - - if (x == -1 && y == 0) { - score = type; - continue; - } - - screen[{x, y}] = static_cast(type); - } - return score; - } - - void draw_screen(const Screen &screen, std::ostream& output) { - // Determine bounding box - using limits = std::numeric_limits; - - const auto [lower, upper] = aoc2019::bounding_box(screen); - - for (auto y = lower[1]; y <= upper[1]; ++y) { - for (auto x = lower[0]; x <= upper[0]; ++x) { - char c = ' '; - if (auto it = screen.find({x, y}); it != screen.end()) { - switch (it->second) { - case Tile::EMPTY: - c = ' '; - break; - - case Tile::BALL: - c = '*'; - break; - - case Tile::BLOCK: - c = '='; - break; - - case Tile::PADDLE: - c = '_'; - break; - - case Tile::WALL: - c = '#'; - break; - } - } - - output << c; - } - - output << '\n'; - } - } - - auto find_pos(const Screen &screen, Tile to_find) { - return std::find_if(screen.begin(), screen.end(), [to_find](const auto& x) { - return x.second == to_find; - }); - } -} - -void aoc2019::day13_part1(std::istream &input, std::ostream &output) { - Screen screen; - aoc2019::IntCodeComputer computer(aoc2019::IntCodeComputer::read_intcode(input)); - std::deque output_buffer; - computer.connectOutput(output_buffer); - computer.run(); - update_screen(output_buffer, screen); - - output << std::count_if(screen.begin(), screen.end(), [](const auto &x) { return x.second == Tile::BLOCK; }) - << std::endl; -} - -void aoc2019::day13_part2(std::istream &input, std::ostream &output) { - auto program = aoc2019::IntCodeComputer::read_intcode(input); - program[0] = 2; - - aoc2019::IntCodeComputer computer(std::move(program)); - std::deque output_buffer; - computer.connectOutput(output_buffer); - computer.run(); - - Screen screen; - - std::int64_t score = 0; - - while (!computer.isTerminated()) { - computer.run(); - auto new_score = update_screen(output_buffer, screen); - if (new_score) { - score = *new_score; - } - -#ifdef ANIMATE_DAY13 - output << "Score: " << score << std::endl; - draw_screen(screen, output); - std::this_thread::sleep_for(std::chrono::milliseconds(40)); -#endif - - auto ball_pos = find_pos(screen, Tile::BALL)->first; - auto paddle_pos = find_pos(screen, Tile::PADDLE)->first; - - if (ball_pos[0] < paddle_pos[0]) { - computer.sendInput(-1); - } else if (ball_pos[0] > paddle_pos[0]) { - computer.sendInput(1); - } else { - computer.sendInput(0); - } - } - - output << score << std::endl; -} diff --git a/2019/src/day14.cpp b/2019/src/day14.cpp deleted file mode 100644 index 2abebfd..0000000 --- a/2019/src/day14.cpp +++ /dev/null @@ -1,146 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include "days.hpp" -#include "utils.hpp" - -namespace { - typedef std::pair requirement_t; - typedef std::vector reqlist_t; - - std::map read_recipes(std::istream &input) { - std::map recipes; - - std::string buffer; - std::regex listing_regex("(\\d+) ([A-Z]+)"); - - std::int64_t amount; - - while (std::getline(input, buffer)) { - reqlist_t requirements, production; - - std::string_view line = buffer; - - auto split_point = line.find(" => "); - - auto requirements_part = line.substr(0, split_point); - auto production_part = line.substr(split_point + 4); - - for (auto it = std::regex_token_iterator(requirements_part.begin(), requirements_part.end(), listing_regex, - {1, 2}); it != std::cregex_token_iterator(); ++it) { - std::from_chars(it->first, it->second, amount); - ++it; - - requirements.emplace_back(*it, amount); - } - - for (auto it = std::regex_token_iterator(production_part.begin(), production_part.end(), listing_regex, - {1, 2}); it != std::cregex_token_iterator(); ++it) { - std::from_chars(it->first, it->second, amount); - ++it; - - production.emplace_back(*it, amount); - } - - recipes[std::move(production)] = std::move(requirements); - } - - return recipes; - } - - template - std::unordered_map element_creators(const Map &map) { - std::unordered_map inverted; - - for (auto &entry : map) { - for (auto &x : entry.first) { - inverted[x.first] = entry.first; - } - } - - return inverted; - } - - std::vector topological_order(const std::map &recipes) { - std::vector order; - - std::unordered_map> edges; - for (auto &entry : recipes) { - for (auto &production : entry.first) { - std::transform(entry.second.begin(), entry.second.end(), std::back_inserter(edges[production.first]), - [](const auto &x) { - return x.first; - }); - } - } - - return aoc2019::topological_sort(edges); - } - - std::int64_t ore_to_fuel(const std::map &recipes, std::int64_t amount = 1) { - auto inverted = element_creators(recipes); - auto order = topological_order(recipes); - - std::unordered_map total_requirements; - total_requirements["FUEL"] = amount; - - for (const auto &element : order) { - if (element == "ORE") { - break; - } - - const auto number_required = total_requirements[element]; - if (number_required <= 0) { - continue; - } - - const auto &productions = inverted.at(element); - const auto &requirements = recipes.at(productions); - - auto number_produced = std::find_if(productions.begin(), productions.end(), - [element](const auto &x) { return x.first == element; })->second; - - auto productions_needed = number_required / number_produced + (number_required % number_produced ? 1 : 0); - - for (auto &requirement : requirements) { - total_requirements[requirement.first] += requirement.second * productions_needed; - } - - for (auto &production : productions) { - total_requirements[production.first] -= productions_needed * production.second; - } - } - - return total_requirements["ORE"]; - } -} - -void aoc2019::day14_part1(std::istream &input, std::ostream &output) { - auto recipes = read_recipes(input); - - output << ore_to_fuel(recipes) << std::endl; -} - -void aoc2019::day14_part2(std::istream &input, std::ostream &output) { - auto recipes = read_recipes(input); - - constexpr std::int64_t ore_stock = 1000000000000; - - std::int64_t min = 1, max = ore_stock + 1; // assumption: 1 ore produces < 1 fuel. - while (max - min > 1) { - auto cur = (max + min) / 2; - - if (ore_to_fuel(recipes, cur) < ore_stock) { - min = cur; - } else { - max = cur - 1; - } - } - - output << (max + min) / 2 << std::endl; -} diff --git a/2019/src/day15.cpp b/2019/src/day15.cpp deleted file mode 100644 index 8c0d90b..0000000 --- a/2019/src/day15.cpp +++ /dev/null @@ -1,153 +0,0 @@ -#include -#include -#include -#include "days.hpp" -#include "utils.hpp" -#include "point.hpp" - -namespace { - typedef aoc2019::Point point_t; - - enum class Tile { - Wall, - Empty, - Oxygen, - }; - - enum class Mark { - None, - Temp, - Permanent, - }; - - const std::unordered_map DIRECTIONS{ - {{0, -1}, 1}, - {{0, 1}, 2}, - {{-1, 0}, 3}, - {{1, 0}, 4}, - }; - - std::unordered_map read_map(std::istream &input) { - aoc2019::IntCodeComputer computer(input); - std::deque output_buffer; - computer.connectOutput(output_buffer); - - point_t pos = {0, 0}; - std::deque prev; - std::unordered_map map{{pos, Tile::Empty}}; - std::unordered_map markings{{pos, Mark::Temp}}; - - computer.run(); - - while (true) { - std::optional next_step; - - for (auto &direction : DIRECTIONS) { - if (markings[pos + direction.first] == Mark::None) { - next_step = direction.first; - break; - } - } - - if (next_step) { - const auto next_pos = pos + *next_step; - computer.sendInput(DIRECTIONS.at(*next_step)); - computer.run(); - - assert(!output_buffer.empty()); - - switch (output_buffer.front()) { - case 0: - markings[next_pos] = Mark::Permanent; - map[next_pos] = Tile::Wall; - break; - - case 1: - case 2: - prev.push_front(pos); - markings[next_pos] = Mark::Temp; - map[next_pos] = static_cast(output_buffer.front()); - pos = next_pos; - break; - - default: - throw std::domain_error("Invalid data from remote"); - } - output_buffer.pop_front(); - assert(output_buffer.empty()); - } else { - markings[pos] = Mark::Permanent; - // Nowhere left to go, move back. - if (prev.empty()) { - return map; - } - - auto prev_pos = prev.front(); - auto step = DIRECTIONS.at(prev_pos - pos); - prev.pop_front(); - computer.sendInput(step); - computer.run(); - // We should be able to travel back - assert(output_buffer.front() == 1); - output_buffer.pop_front(); - pos = prev_pos; - } - } - } - - template - int bfs(const std::unordered_map &map, point_t starting_point, Callback callback) { - std::deque> todo{{starting_point, 0}}; - std::unordered_set visited{{0, 0}}; - - int max_dist = 0; - - while (!todo.empty()) { - auto[cur, dist] = todo.front(); - todo.pop_front(); - - max_dist = std::max(max_dist, dist); - - for (auto &dir : DIRECTIONS) { - auto new_pos = cur + dir.first; - if (!visited.count(new_pos)) { - visited.insert(new_pos); - - if (callback(map.at(new_pos))) { - return dist + 1; - } - - switch (map.at(new_pos)) { - case Tile::Oxygen: - case Tile::Empty: - todo.emplace_back(new_pos, dist + 1); - break; - - default: - break; - } - } - } - } - - return max_dist; - } -} - -void aoc2019::day15_part1(std::istream &input, std::ostream &output) { - const auto map = read_map(input); - - auto dist = bfs(map, {0, 0}, [](Tile x) { return x == Tile::Oxygen; }); - - output << dist << std::endl; -} - -void aoc2019::day15_part2(std::istream &input, std::ostream &output) { - const auto map = read_map(input); - - auto starting_point = std::find_if(map.begin(), map.end(), [](auto &x) { return x.second == Tile::Oxygen; })->first; - - auto dist = bfs(map, starting_point, [](Tile x) { return false; }); - - output << dist << std::endl; -} diff --git a/2019/src/day16.cpp b/2019/src/day16.cpp deleted file mode 100644 index 5f83a32..0000000 --- a/2019/src/day16.cpp +++ /dev/null @@ -1,117 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include "days.hpp" -#include "utils.hpp" - -namespace { - std::array base_pattern{0, 1, 0, -1}; - - int get_modifier(int rank, int pos) { - pos += 1; - pos /= rank + 1; - - return base_pattern[pos % 4]; - } - - std::vector read_input(std::istream &input) { - std::vector result; - - for (char c; input >> c;) { - assert(std::isdigit(c)); - result.push_back(c - '0'); - } - - return result; - } - - void simulate(std::vector numbers, std::ostream &output) { - std::vector new_numbers(numbers.size()); - std::vector partial_sums(numbers.size()); - - for (int i = 0; i < 100; ++i) { - for (int rank = 0; rank < numbers.size(); ++rank) { - std::partial_sum(numbers.begin() + rank, numbers.end(), partial_sums.begin() + rank); - int n = 0; - for (int pos = rank; pos < numbers.size(); pos += rank + 1) { - int run = std::min(rank + 1, (int) numbers.size() - pos); - if (int modifier = get_modifier(rank, pos); modifier) { - n += modifier * (partial_sums[pos + run - 1] - partial_sums[pos] + numbers[pos]); - } - } - - n = std::abs(n % 10); - - new_numbers[rank] = n; - } - - std::swap(numbers, new_numbers); - } - - std::copy(numbers.begin(), numbers.begin() + 8, std::ostream_iterator(output)); - output << std::endl; - } - - int get_offset(const std::vector &numbers) { - int offset = 0; - for (int i = 0; i < 7; ++i) { - offset *= 10; - offset += numbers[i]; - } - - return offset; - } - - std::vector numbers_from_offset(const std::vector &numbers, unsigned int offset) { - constexpr auto repetitions = 10000; - const auto desired_length = repetitions * numbers.size() - offset; - - std::vector numbers_after; - numbers_after.reserve(desired_length); - numbers_after.insert(numbers_after.end(), numbers.begin() + (offset % numbers.size()), numbers.end()); - - while (numbers_after.size() < desired_length) { - auto remaining = desired_length - numbers_after.size(); - if (remaining >= numbers.size()) { - numbers_after.insert(numbers_after.end(), numbers.begin(), numbers.end()); - } else { - numbers_after.insert(numbers_after.end(), numbers.begin(), numbers.end() + remaining); - } - } - - return numbers_after; - } -} - -void aoc2019::day16_part1(std::istream &input, std::ostream &output) { - auto numbers = read_input(input); - - simulate(std::move(numbers), output); -} - -void aoc2019::day16_part2(std::istream &input, std::ostream &output) { - auto numbers = read_input(input); - - const int offset = get_offset(numbers); - - numbers = numbers_from_offset(numbers, offset); - - std::vector new_numbers(numbers.size()); - std::vector partial_sums(numbers.size()); - - for (int i = 0; i < 100; ++i) { - std::partial_sum(numbers.rbegin(), numbers.rend(), partial_sums.rbegin()); - - std::transform(partial_sums.begin(), partial_sums.end(), new_numbers.begin(), [](int x) { - return x % 10; - }); - - std::swap(numbers, new_numbers); - } - - std::copy(numbers.begin(), numbers.begin() + 8, std::ostream_iterator(output)); - output << std::endl; -} diff --git a/2019/src/day17.cpp b/2019/src/day17.cpp deleted file mode 100644 index 3252eb1..0000000 --- a/2019/src/day17.cpp +++ /dev/null @@ -1,103 +0,0 @@ -#include -#include -#include -#include "days.hpp" -#include "utils.hpp" -#include "point.hpp" - -namespace { - typedef aoc2019::Point point_t; - - const std::unordered_map DIRECTIONS{ - {'^', {0, -1}}, - {'>', {0, 1}}, - {'v', {1, 0}}, - {'<', {-1, 0}}, - }; - - std::unordered_map read_scaffold(const std::deque &data) { - int x = 0; - int y = 0; - std::unordered_map map; - for (auto n : data) { - if (n == '\n') { - if (x == 0) { - // Double newline, end of map - break; - } - ++y; - x = 0; - continue; - } else { - map[{x, y}] = (char) n; - ++x; - } - } - - return map; - } -} - -void aoc2019::day17_part1(std::istream &input, std::ostream &output) { - IntCodeComputer computer(input); - std::deque output_buffer; - computer.connectOutput(output_buffer); - - computer.run(); - - const auto map = read_scaffold(output_buffer); - - std::int64_t total = 0; - - for (auto &entry : map) { - if (entry.second == '.') continue; - - bool is_intersection = std::all_of(DIRECTIONS.begin(), DIRECTIONS.end(), [&map, &entry](auto &x) { - auto it = map.find(x.second + entry.first); - return it != map.end() && it->second != '.'; - }); - - if (is_intersection) { - total += entry.first[0] * entry.first[1]; - } - } - - output << total << std::endl; -} - -void aoc2019::day17_part2(std::istream &input, std::ostream &output) { - using namespace std::literals; - - aoc2019::IntCodeComputer computer(input); - computer[0] = 2; - std::deque output_buffer; - computer.connectOutput(output_buffer); - - std::array programs = { - "L,6,R,8,L,4,R,8,L,12\n", - "L,12,R,10,L,4\n", - "L,12,L,6,L,4,L,4\n", - }; - - auto combined_programs = "A,B,B,C,B,C,B,C,A,A\n"sv; - - computer.sendInputs(combined_programs); - - for (auto program : programs) { - computer.sendInputs(program); - } - - // Don't give me output. - computer.sendInputs("n\n"); - - computer.run(); - - assert(!output_buffer.empty()); - - if (output_buffer.size() == 1) { - output << output_buffer.front() << std::endl; - } else { - std::copy(output_buffer.begin(), output_buffer.end(), std::ostreambuf_iterator(output)); - output << output_buffer.back() << std::endl; - } -} diff --git a/2019/src/day17/route-map.py b/2019/src/day17/route-map.py deleted file mode 100644 index 873b2af..0000000 --- a/2019/src/day17/route-map.py +++ /dev/null @@ -1,76 +0,0 @@ -import fileinput -import sys - - -def turn_left(direction): - x, y = direction - return (y, -x) - - -def turn_right(direction): - x, y = direction - return (-y, x) - - -def add(pos, direction): - return tuple(a + b for a, b in zip(pos, direction)) - - -def main(): - chart = [line.strip() for line in fileinput.input()] - - pos = None - - for y, line in enumerate(chart): - x = line.find('^') - if x >= 0: - pos = (x, y) - break - - if not pos: - sys.exit('starting point not found') - - route = ['L'] - - direction = (-1, 0) - - def bounds_check(pos): - x, y = pos - - return x >= 0 and y >= 0 and y < len(chart) - - while True: - # try to move forward - next_pos = add(direction, pos) - dist = 0 - - while bounds_check(next_pos) and chart[next_pos[1]][next_pos[0]] == '#': - dist += 1 - pos = next_pos - next_pos = add(direction, pos) - - if dist: - route.append(dist) - else: - break - - for move, new_dir in zip(('L', 'R'), (turn_left(direction), turn_right(direction))): - next_pos = add(pos, new_dir) - if bounds_check(next_pos) and chart[next_pos[1]][next_pos[0]] == '#': - route.append(move) - direction = new_dir - break - - printable_route = [] - for x in route: - if x == 'L' or x == 'R': - printable_route.append(x) - else: - printable_route += ['M'] * x - - print(','.join(str(x) for x in route)) - print(','.join(printable_route)) - - -if __name__ == '__main__': - main() diff --git a/2019/src/day18.cpp b/2019/src/day18.cpp deleted file mode 100644 index e5c8452..0000000 --- a/2019/src/day18.cpp +++ /dev/null @@ -1,226 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include "days.hpp" -#include "point.hpp" - -static_assert(sizeof(int) >= 4, "Int should be at least 32 bits."); - -using namespace std::string_view_literals; - -namespace { - typedef aoc2019::Point point_t; - - typedef std::vector map_t; - - std::array DIRECTIONS = {{ - {0, -1}, - {0, 1}, - {-1, 0}, - {1, 0}, - }}; - - map_t read_map(std::istream &input) { - std::string buffer; - map_t map; - - while (std::getline(input, buffer)) { - map.push_back(buffer); - } - - return map; - } - - point_t find(const std::vector &map, char needle) { - for (int y = 0; y < map.size(); ++y) { - auto x = map[y].find(needle); - if (x != std::string::npos) { - return {(int) x, y}; - } - } - - throw std::invalid_argument("Can't find it!"); - } - - std::vector> find_edges(const map_t &map, point_t starting_point) { - std::vector> edges; - std::queue> todo; - todo.emplace(0, starting_point); - - std::unordered_set visited{starting_point}; - - while (!todo.empty()) { - const auto[dist, pos] = todo.front(); - todo.pop(); - - for (auto &direction : DIRECTIONS) { - auto next_pos = pos + direction; - const char at = map[next_pos[1]][next_pos[0]]; - - if (at == '#' || visited.count(next_pos)) { - // Wall or already visited, ignore - continue; - } - - visited.insert(next_pos); - - if (std::isalpha(at)) { - // Don't walk through stuff - edges.emplace_back(at, dist + 1); - } else { - todo.emplace(dist + 1, next_pos); - } - } - } - - return edges; - } - - auto compute_implied_graph(const map_t &map) { - std::unordered_map>> implied_graph; - - for (int y = 0; y < map.size(); ++y) { - for (int x = 0; x < map[y].size(); ++x) { - char at = map[y][x]; - if ("@/^*"sv.find(at) != std::string_view::npos || std::isalpha(at)) { - implied_graph[at] = find_edges(map, {x, y}); - } - } - } - - return implied_graph; - } - - inline unsigned int key_index(char c) { - return 1u << static_cast(c - 'A'); - } -} - -void aoc2019::day18_part1(std::istream &input, std::ostream &output) { - using state_t = std::tuple; - - const auto map = read_map(input); - - auto implied_graph = compute_implied_graph(map); - - std::priority_queue, std::vector>, std::greater<>> todo; - std::map visited; - todo.emplace(0, std::make_pair(0, '@')); - - auto target_size = std::count_if(implied_graph.cbegin(), implied_graph.cend(), - [](auto &x) { return std::islower(x.first); }); - - while (!todo.empty()) { - const auto[dist, state] = todo.top(); - todo.pop(); - - if (visited[state] < dist) { - continue; - } - - auto[keys, pos] = state; - - if (std::__popcount(keys) == target_size) { - output << dist << std::endl; - return; - } - - for (const auto &edge : implied_graph.at(pos)) { - auto next_dist = dist + edge.second; - auto next_keys = keys; - if (std::islower(edge.first)) { - // Add the key to our collection - next_keys |= key_index(edge.first);; - } else if (std::isupper(edge.first)) { - // Check if we have the required key already - if (!(next_keys & key_index(edge.first))) { - continue; - } - } - - state_t next_state = {next_keys, edge.first}; - if (auto it = visited.find(next_state); it == visited.end() || it->second > next_dist) { - visited[next_state] = next_dist; - todo.emplace(next_dist, next_state); - } - - } - } - - throw std::logic_error("Should have terminated by now."); -} - -void aoc2019::day18_part2(std::istream &input, std::ostream &output) { - using state_t = std::pair>; - - auto map = read_map(input); - - // problem statement says to duplicate @ but where's the fun in that - const auto initial_pos = find(map, '@'); - - // problem statement says to duplicate @ but where's the fun in that, let's have different starting positions - std::array overlay = { - "@#*", - "###", - "^#/", - }; - - for (int y = 0; y < 3; ++y) { - auto &row = map[initial_pos[1] + y - 1]; - std::copy(overlay[y].begin(), overlay[y].end(), row.data() + initial_pos[0] - 1); - } - - const auto implied_graph = compute_implied_graph(map); - - std::priority_queue, std::vector>, std::greater<>> todo; - std::map, int> visited; - todo.emplace(0, state_t(0, {'@', '*', '^', '/'})); - - auto target_size = std::count_if(implied_graph.cbegin(), implied_graph.cend(), - [](auto &x) { return std::islower(x.first); }); - - - while (!todo.empty()) { - const auto[dist, state] = todo.top(); - todo.pop(); - - auto[keys, pos] = state; - - if (std::__popcount(keys) == target_size) { - output << dist << std::endl; - return; - } - - for (int i = 0; i < 4; ++i) { - auto next_pos = pos; - for (const auto &edge : implied_graph.at(pos[i])) { - auto next_dist = dist + edge.second; - auto next_keys = keys; - if (std::islower(edge.first)) { - // Add the key to our collection - next_keys |= key_index(edge.first);; - } else if (std::isupper(edge.first)) { - // Check if we have the required key already - if (!(next_keys & key_index(edge.first))) { - continue; - } - } - - next_pos[i] = edge.first; - - state_t next_state = {next_keys, next_pos}; - if (auto it = visited.find({next_keys, next_pos[i]}); it == visited.end() || it->second > next_dist) { - visited[{next_keys, next_pos[i]}] = next_dist; - todo.emplace(next_dist, next_state); - } - } - } - } - - - output << "Not implemented\n"; -} diff --git a/2019/src/day19.cpp b/2019/src/day19.cpp deleted file mode 100644 index 15eea3c..0000000 --- a/2019/src/day19.cpp +++ /dev/null @@ -1,89 +0,0 @@ -#include -#include -#include -#include "days.hpp" -#include "utils.hpp" - -namespace { - bool bounds_check(aoc2019::IntCodeComputer computer, std::int64_t x, std::int64_t y) { - std::deque output_buffer; - computer.connectOutput(output_buffer); - - computer.sendInput(x); - computer.sendInput(y); - - computer.run(); - assert(computer.isTerminated()); - assert(!output_buffer.empty()); - - return output_buffer.front(); - } - - class Beam { - private: - aoc2019::IntCodeComputer computer; - std::int64_t last_width = 1; - std::int64_t last_start = 0; - std::int64_t y = 0; - - public: - Beam(std::istream &input) : computer(input) {}; - - std::pair next() { - auto x = last_start; - - while (!bounds_check(computer, x, y)) { - ++x; - } - - last_start = x; - x += last_width - 1; - - while (bounds_check(computer, x, y)) { - ++x; - } - - last_width = x - last_start; - ++y; - - return {last_start, last_width}; - } - }; -} - -void aoc2019::day19_part1(std::istream &input, std::ostream &output) { - Beam beam(input); - - std::int64_t covered = 0; - for (std::int64_t y = 0; y < 50; ++y) { - const auto[start, width] = beam.next(); - - if (start >= 50) break; - - covered += std::min(50 - start, width); - } - - output << covered << std::endl; -} - -void aoc2019::day19_part2(std::istream &input, std::ostream &output) { - Beam beam(input); - std::queue beam_ends; - - constexpr std::int64_t DIMENSION = 100; - - for (std::int64_t y = 0; true; ++y) { - const auto[start, width] = beam.next(); - - beam_ends.push(start + width); - if (beam_ends.size() == DIMENSION) { - auto end = beam_ends.front(); - if (end - start >= DIMENSION) { - auto result = start * 10000 + y - DIMENSION + 1; - output << result << std::endl; - return; - } - beam_ends.pop(); - } - } -} diff --git a/2019/src/day20.cpp b/2019/src/day20.cpp deleted file mode 100644 index d8087f6..0000000 --- a/2019/src/day20.cpp +++ /dev/null @@ -1,215 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include "days.hpp" -#include "point.hpp" - -namespace { - typedef aoc2019::Point point_t; - typedef std::vector map_t; - - std::array DIRECTIONS = {{ - {0, -1}, - {0, 1}, - {-1, 0}, - {1, 0}, - }}; - - std::vector read_map(std::istream &input) { - std::string buffer; - std::vector map; - - while (std::getline(input, buffer)) { - map.push_back(buffer); - } - - return map; - } - - auto get_portals(const map_t &map) { - std::unordered_map portals; - - // First find horizontal portals - for (int y = 0; y < map.size(); ++y) { - for (int x = 0; x < map[y].size() - 1; ++x) { - if (std::isalpha(map[y][x]) && std::isalpha(map[y][x + 1])) { - // find out the entry point - point_t entry_point = {0, y}; - if (x > 0 && map[y][x - 1] == '.') { - entry_point[0] = x - 1; - } else { - entry_point[0] = x + 2; - } - - portals[entry_point] = map[y].substr(x, 2); - } - } - } - - char name[3] = {0, 0, 0}; - for (int x = 0; x < map[0].size(); ++x) { - for (int y = 0; y < map.size() - 1; ++y) { - if (std::isalpha(map[y][x]) && std::isalpha(map[y + 1][x])) { - name[0] = map[y][x]; - name[1] = map[y + 1][x]; - - point_t entry_point = {x, 0}; - if (y > 0 && map[y - 1][x] == '.') { - entry_point[1] = y - 1; - } else { - entry_point[1] = y + 2; - } - - portals[entry_point] = name; - } - } - } - - return portals; - } - - std::unordered_map>> - get_implicit_graph(const map_t &map, const std::unordered_map &portals) { - std::unordered_map half_links; - - std::unordered_map>> graph; - - for (auto &entry : portals) { - if (auto it = half_links.find(entry.second); it != half_links.end()) { - // Connect up the portals - graph[it->second].emplace_back(1, entry.first); - graph[entry.first].emplace_back(1, it->second); - } else { - half_links[entry.second] = entry.first; - } - - // Do a BFS from the node to see what we can reach. - std::deque> todo{{0, entry.first}}; - std::unordered_set visited{entry.first}; - - while (!todo.empty()) { - const auto[dist, pos] = todo.front(); - todo.pop_front(); - - for (auto &direction : DIRECTIONS) { - auto next_pos = pos + direction; - - if (map[next_pos[1]][next_pos[0]] != '.' || visited.count(next_pos)) { - continue; - } - - if (portals.count(next_pos)) { - graph[entry.first].emplace_back(dist + 1, next_pos); - } - - todo.emplace_back(dist + 1, next_pos); - visited.insert(next_pos); - } - } - } - - return graph; - } -} - -void aoc2019::day20_part1(std::istream &input, std::ostream &output) { - const auto map = read_map(input); - const auto portals = get_portals(map); - - const auto starting_point = std::find_if(portals.begin(), portals.end(), [](auto &x) { - return x.second == "AA"; - })->first; - - auto graph = get_implicit_graph(map, portals); - - std::unordered_set visited; - std::priority_queue, std::vector>, std::greater<>> todo; - todo.emplace(0, starting_point); - - while (!todo.empty()) { - const auto[dist, pos] = todo.top(); - todo.pop(); - - if (visited.count(pos)) { - continue; - } - - visited.insert(pos); - - if (portals.at(pos) == "ZZ") { - output << dist << std::endl; - return; - } - - for (auto &edge : graph[pos]) { - if (visited.count(edge.second)) { - continue; - } - - todo.emplace(dist + edge.first, edge.second); - } - } - - throw std::domain_error("No valid route."); -} - -void aoc2019::day20_part2(std::istream &input, std::ostream &output) { - const auto map = read_map(input); - const auto portals = get_portals(map); - - using state_t = std::pair; - - const auto starting_point = std::find_if(portals.begin(), portals.end(), [](auto &x) { - return x.second == "AA"; - })->first; - - auto graph = get_implicit_graph(map, portals); - - std::set visited; - std::priority_queue, std::vector>, std::greater<>> todo; - todo.emplace(0, 0, starting_point); - - const int outer_x_min = 2; - const int outer_x_max = map[0].size() - 3; - const int outer_y_min = 2; - const int outer_y_max = map.size() - 3; - - while (!todo.empty()) { - const auto[dist, level, pos] = todo.top(); - todo.pop(); - - if (visited.count({level, pos})) { - continue; - } - - visited.emplace(level, pos); - - if (level == 0 && portals.at(pos) == "ZZ") { - output << dist << std::endl; - return; - } - - for (auto &edge : graph[pos]) { - int mod = 0; - if (edge.first == 1) { - // Taking a portal, determine which level we're going to - if (pos[0] == outer_x_max || pos[0] == outer_x_min || pos[1] == outer_y_max || pos[1] == outer_y_min) { - mod = -1; - } else { - mod = 1; - } - } - - if (level + mod < 0 || visited.count({level + mod, edge.second})) { - continue; - } - - todo.emplace(dist + edge.first, level + mod, edge.second); - } - } - - throw std::domain_error("No valid route."); -} diff --git a/2019/src/day21.cpp b/2019/src/day21.cpp deleted file mode 100644 index d231041..0000000 --- a/2019/src/day21.cpp +++ /dev/null @@ -1,47 +0,0 @@ -#include -#include "days.hpp" -#include "utils.hpp" - -namespace { - void solve(std::istream &input, std::string_view program, std::ostream &output) { - aoc2019::IntCodeComputer computer(input); - std::deque output_buffer; - computer.connectOutput(output_buffer); - computer.run(); - output_buffer.clear(); - - computer.sendInputs(program); - - computer.run(); - if (output_buffer.back() < 127) { - for (char c : output_buffer) { - output << c; - } - } else { - output << output_buffer.back() << std::endl; - } - } -} - -void aoc2019::day21_part1(std::istream &input, std::ostream &output) { - std::string_view program = "OR A J\n" // Check if any of the next 3 places is a hole - "AND B J\n" - "AND C J\n" - "NOT J J\n" - "AND D J\n" // Jump if the landing space is clear - "WALK\n"; - - solve(input, program, output); -} - -void aoc2019::day21_part2(std::istream &input, std::ostream &output) { - std::string_view program = "NOT H J\n" // If you can safely jump twice - "OR C J\n" // And either of the next 3 places contains a hole - "AND A J\n" - "AND B J\n" - "NOT J J\n" - "AND D J\n" // And we can land our first jump, then jump. - "RUN\n"; - - solve(input, program, output); -} diff --git a/2019/src/day22.cpp b/2019/src/day22.cpp deleted file mode 100644 index 3900157..0000000 --- a/2019/src/day22.cpp +++ /dev/null @@ -1,149 +0,0 @@ -#include -#include -#include "days.hpp" -#include "utils.hpp" - -namespace { - enum class Operation { - Stack, - Deal, - Cut - }; - - using Move = std::pair; - - std::vector read_moves(std::istream &input) { - std::string buffer; - std::vector moves; - - while (std::getline(input, buffer)) { - std::string_view line = buffer; - if (!line.find("deal into new stack")) { - moves.emplace_back(Operation::Stack, 0); - } else if (!line.find("deal with increment ")) { - int new_increment; - aoc2019::from_chars(line.substr(20), new_increment); - moves.emplace_back(Operation::Deal, new_increment); - } else { - // cut - int new_offset; - aoc2019::from_chars(line.substr(4), new_offset); - - moves.emplace_back(Operation::Cut, new_offset); - } - } - - return moves; - } - - constexpr std::int64_t mmi(std::int64_t a, std::int64_t n) { - std::int64_t t = 0, newt = 1, r = n, newr = a; - - while (newr != 0) { - auto q = r / newr; - // Poor man's simultaneous assignment - std::tie(t, newt) = std::make_tuple(newt, t - q * newt); - std::tie(r, newr) = std::make_tuple(newr, r - q * newr); - } - - if (r > 1) { - throw std::invalid_argument("Not invertible."); - } - - if (t < 0) t += n; - - assert((t * a) % n == 1); - - return t; - } - - constexpr std::pair pow(std::int64_t a, std::int64_t b, std::int64_t n, const std::int64_t M) { - __int128 ra = 0, rb = 0; - - while (n > 0) { - if (n % 2) { - ra = (ra + a) % M; - rb = (rb + b) % M; - } - - // f(x) = ax + b - // f(f(x)) = a(ax + b) + b - // = aax + ab + b - __int128 na = a * (__int128) a; - __int128 nb = b * (__int128) a + b; - - a = na % M; - b = nb % M; - - n /= 2; - } - - return {ra, rb}; - } -} - -void aoc2019::day22_part1(std::istream &input, std::ostream &output) { - constexpr int DECK_SIZE = 10007; - - int pos = 2019; - - for (auto move : read_moves(input)) { - int argument = move.second; - switch (move.first) { - case Operation::Stack: - pos = DECK_SIZE - 1 - pos; - break; - - case Operation::Deal: - pos = pos * argument % DECK_SIZE; - break; - - case Operation::Cut: - pos = (pos - argument) % DECK_SIZE; - if (pos < 0) pos += DECK_SIZE; - break; - } - } - - output << pos << std::endl; -} - -void aoc2019::day22_part2(std::istream &input, std::ostream &output) { - constexpr std::int64_t DECK_SIZE = 119315717514047; - constexpr std::int64_t SHUFFLES = 101741582076661; - - assert(mmi(3, 11) == 4); - - std::int64_t a = 1, b = 0; - - for (auto move : read_moves(input)) { - std::int64_t argument = move.second; - switch (move.first) { - case Operation::Stack: - a = -a; - b = DECK_SIZE - b - 1; - break; - - case Operation::Cut: - b = (b + argument) % DECK_SIZE; - break; - - case Operation::Deal: - __int128 inv = mmi(argument, DECK_SIZE); - a = (a * inv) % DECK_SIZE; - b = (b * inv) % DECK_SIZE; - break; - } - } - - const auto[ra, rb] = pow(a, b, SHUFFLES, DECK_SIZE); - - output << ra << ',' << rb << std::endl; - - auto result = (2020 * ra + rb) % DECK_SIZE; - if (result < 0) { - result += DECK_SIZE; - } - - output << result << std::endl; -} diff --git a/2019/src/day23.cpp b/2019/src/day23.cpp deleted file mode 100644 index 383e9f5..0000000 --- a/2019/src/day23.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include "days.hpp" - -void aoc2019::day23_part1(std::istream &input, std::ostream &output) { - output << "Not implemented\n"; -} - -void aoc2019::day23_part2(std::istream &input, std::ostream &output) { - output << "Not implemented\n"; -} diff --git a/2019/src/day24.cpp b/2019/src/day24.cpp deleted file mode 100644 index 3d69eea..0000000 --- a/2019/src/day24.cpp +++ /dev/null @@ -1,188 +0,0 @@ -#include -#include -#include -#include -#include -#include "days.hpp" - -namespace { - using field_t = std::array, 5>; - - constexpr int EDGE = 4; - constexpr int MIDPOINT = 2; - - field_t read_input(std::istream &input) { - std::string buffer; - field_t map; - - int y = 0; - - while (std::getline(input, buffer)) { - auto &row = map[y++]; - - std::transform(buffer.begin(), buffer.end(), row.begin(), [](char c) { return c == '#'; }); - } - - return map; - } - - void next_gen(const field_t &source, field_t &sink) { - for (int y = 0; y < source.size(); ++y) { - for (int x = 0; x < source[y].size(); ++x) { - int neighbours = source[y][x] ? -1 : 0; - for (int dy = -1; dy <= 1; ++dy) { - if (dy + y < 0 || dy + y >= source.size()) { - continue; - } - for (int dx = -1; dx <= 1; ++dx) { - if (dx + x < 0 || dx + x >= source[y].size() || dx * dy) { - continue; - } - neighbours += source[y + dy][x + dx]; - } - } - - sink[y][x] = neighbours == 1 || (!source[y][x] && neighbours == 2); - } - } - } - - int num_bees(const field_t &field) { - int total = 0; - for (auto &row : field) { - total += std::count(row.begin(), row.end(), true); - } - - return total; - } - - std::unordered_map advance(const std::unordered_map &state) { - const auto dimension_range = std::minmax_element(state.begin(), state.end()); - const auto min = dimension_range.first->first - 1; - const auto max = dimension_range.second->first + 1; - - std::unordered_map next_gen; - - auto has_bee = [&state](int dimension, int x, int y) { - if (auto it = state.find(dimension); it != state.end()) { - return it->second[y][x]; - } - - return false; - }; - - for (int dimension = min; dimension <= max; ++dimension) { - field_t field{}; - if (auto it = state.find(dimension); it != state.end()) { - field = it->second; - } - - auto get_neighbours = [has_bee,dimension](int x, int y) { - int neighbours = 0; - - // Cell above - if (y == 0) { - neighbours += has_bee(dimension + 1, MIDPOINT, 1); - } else if (y == 3 && x == MIDPOINT) { - for (int sx = 0; sx < 5; ++sx) { - neighbours += has_bee(dimension - 1, sx, EDGE); - } - } else { - neighbours += has_bee(dimension, x, y - 1); - } - - // Cell below - if (y == EDGE) { - neighbours += has_bee(dimension + 1, MIDPOINT, 3); - } else if (y == 1 && x == MIDPOINT) { - for (int sx = 0; sx < 5; ++sx) { - neighbours += has_bee(dimension - 1, sx, 0); - } - } else { - neighbours += has_bee(dimension, x, y + 1); - } - - // Cell left - if (x == 0) { - neighbours += has_bee(dimension + 1, 1, 2); - } else if (x == 3 && y == MIDPOINT) { - for (int sy = 0; sy < 5; ++sy) { - neighbours += has_bee(dimension - 1, EDGE, sy); - } - } else { - neighbours += has_bee(dimension, x - 1, y); - } - - // Cell right - if (x == EDGE) { - neighbours += has_bee(dimension + 1, 3, MIDPOINT); - } else if (x == 1 && y == MIDPOINT) { - for (int sy = 0; sy < 5; ++sy) { - neighbours += has_bee(dimension - 1, 0, sy); - } - } else { - neighbours += has_bee(dimension, x + 1, y); - } - - return neighbours; - }; - - - for (int y = 0; y < 5; ++y) { - for (int x = 0; x < 5; ++x) { - auto neighbours = get_neighbours(x, y); - field[y][x] = neighbours == 1 || (neighbours == 2 && !field[y][x]); - } - } - - // Don't evolve the midpoint. - field[2][2] = false; - - if (num_bees(field) || (dimension != min && dimension != max)) { - next_gen[dimension] = field; - } - } - - return next_gen; - } -} - -void aoc2019::day24_part1(std::istream &input, std::ostream &output) { - auto map = read_input(input); - auto copy = map; - - std::set seen; - do { - seen.insert(map); - next_gen(map, copy); - std::swap(map, copy); - } while (!seen.count(map)); - - unsigned int pow = 1; - unsigned int diversity = 0; - for (auto &row : map) { - for (auto b : row) { - if (b) { - diversity += pow; - } - - pow <<= 1u; - } - } - output << diversity << std::endl; -} - -void aoc2019::day24_part2(std::istream &input, std::ostream &output) { - std::unordered_map fields; - fields[0] = read_input(input); - - for (int gen = 0; gen < 200; ++gen) { - fields = advance(fields); - } - - int total = std::accumulate(fields.begin(), fields.end(), 0, [](auto cur, const auto &it) { - return cur + num_bees(it.second); - }); - - output << total << std::endl; -} diff --git a/2019/src/day25.cpp b/2019/src/day25.cpp deleted file mode 100644 index 0eb6ade..0000000 --- a/2019/src/day25.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include "days.hpp" - -void aoc2019::day25_part1(std::istream &input, std::ostream &output) { - output << "Not implemented\n"; -} - -void aoc2019::day25_part2(std::istream &input, std::ostream &output) { - output << "Not implemented\n"; -} diff --git a/2019/src/days.hpp b/2019/src/days.hpp deleted file mode 100644 index f34ed64..0000000 --- a/2019/src/days.hpp +++ /dev/null @@ -1,57 +0,0 @@ -#pragma once - -#include - -namespace aoc2019 { - // Declarations of all implemented days. - void day01_part1(std::istream &input, std::ostream &output); - void day01_part2(std::istream &input, std::ostream &output); - void day02_part1(std::istream &input, std::ostream &output); - void day02_part2(std::istream &input, std::ostream &output); - void day03_part1(std::istream &input, std::ostream &output); - void day03_part2(std::istream &input, std::ostream &output); - void day04_part1(std::istream &input, std::ostream &output); - void day04_part2(std::istream &input, std::ostream &output); - void day05_part1(std::istream &input, std::ostream &output); - void day05_part2(std::istream &input, std::ostream &output); - void day06_part1(std::istream &input, std::ostream &output); - void day06_part2(std::istream &input, std::ostream &output); - void day07_part1(std::istream &input, std::ostream &output); - void day07_part2(std::istream &input, std::ostream &output); - void day08_part1(std::istream &input, std::ostream &output); - void day08_part2(std::istream &input, std::ostream &output); - void day09_part1(std::istream &input, std::ostream &output); - void day09_part2(std::istream &input, std::ostream &output); - void day10_part1(std::istream &input, std::ostream &output); - void day10_part2(std::istream &input, std::ostream &output); - void day11_part1(std::istream &input, std::ostream &output); - void day11_part2(std::istream &input, std::ostream &output); - void day12_part1(std::istream &input, std::ostream &output); - void day12_part2(std::istream &input, std::ostream &output); - void day13_part1(std::istream &input, std::ostream &output); - void day13_part2(std::istream &input, std::ostream &output); - void day14_part1(std::istream &input, std::ostream &output); - void day14_part2(std::istream &input, std::ostream &output); - void day15_part1(std::istream &input, std::ostream &output); - void day15_part2(std::istream &input, std::ostream &output); - void day16_part1(std::istream &input, std::ostream &output); - void day16_part2(std::istream &input, std::ostream &output); - void day17_part1(std::istream &input, std::ostream &output); - void day17_part2(std::istream &input, std::ostream &output); - void day18_part1(std::istream &input, std::ostream &output); - void day18_part2(std::istream &input, std::ostream &output); - void day19_part1(std::istream &input, std::ostream &output); - void day19_part2(std::istream &input, std::ostream &output); - void day20_part1(std::istream &input, std::ostream &output); - void day20_part2(std::istream &input, std::ostream &output); - void day21_part1(std::istream &input, std::ostream &output); - void day21_part2(std::istream &input, std::ostream &output); - void day22_part1(std::istream &input, std::ostream &output); - void day22_part2(std::istream &input, std::ostream &output); - void day23_part1(std::istream &input, std::ostream &output); - void day23_part2(std::istream &input, std::ostream &output); - void day24_part1(std::istream &input, std::ostream &output); - void day24_part2(std::istream &input, std::ostream &output); - void day25_part1(std::istream &input, std::ostream &output); - void day25_part2(std::istream &input, std::ostream &output); -} diff --git a/2019/src/implementations.cpp b/2019/src/implementations.cpp deleted file mode 100644 index 9111331..0000000 --- a/2019/src/implementations.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include -#include "days.hpp" -#include "implementations.hpp" - -constexpr const std::array, 25> SOLUTIONS = {{ - {aoc2019::day01_part1, aoc2019::day01_part2}, - {aoc2019::day02_part1, aoc2019::day02_part2}, - {aoc2019::day03_part1, aoc2019::day03_part2}, - {aoc2019::day04_part1, aoc2019::day04_part2}, - {aoc2019::day05_part1, aoc2019::day05_part2}, - {aoc2019::day06_part1, aoc2019::day06_part2}, - {aoc2019::day07_part1, aoc2019::day07_part2}, - {aoc2019::day08_part1, aoc2019::day08_part2}, - {aoc2019::day09_part1, aoc2019::day09_part2}, - {aoc2019::day10_part1, aoc2019::day10_part2}, - {aoc2019::day11_part1, aoc2019::day11_part2}, - {aoc2019::day12_part1, aoc2019::day12_part2}, - {aoc2019::day13_part1, aoc2019::day13_part2}, - {aoc2019::day14_part1, aoc2019::day14_part2}, - {aoc2019::day15_part1, aoc2019::day15_part2}, - {aoc2019::day16_part1, aoc2019::day16_part2}, - {aoc2019::day17_part1, aoc2019::day17_part2}, - {aoc2019::day18_part1, aoc2019::day18_part2}, - {aoc2019::day19_part1, aoc2019::day19_part2}, - {aoc2019::day20_part1, aoc2019::day20_part2}, - {aoc2019::day21_part1, aoc2019::day21_part2}, - {aoc2019::day22_part1, aoc2019::day22_part2}, - {aoc2019::day23_part1, aoc2019::day23_part2}, - {aoc2019::day24_part1, aoc2019::day24_part2}, - {aoc2019::day25_part1, aoc2019::day25_part2}, -}}; - -aoc2019::solution_t aoc2019::get_implementation(int day, bool part2) { - return SOLUTIONS.at(day - 1).at((int) part2); -} diff --git a/2019/src/implementations.hpp b/2019/src/implementations.hpp deleted file mode 100644 index 24e9820..0000000 --- a/2019/src/implementations.hpp +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -#include - -namespace aoc2019 { - typedef void (*solution_t)(std::istream &, std::ostream &); - - solution_t get_implementation(int day, bool part2 = false); -} diff --git a/2019/src/point.hpp b/2019/src/point.hpp deleted file mode 100644 index d123475..0000000 --- a/2019/src/point.hpp +++ /dev/null @@ -1,78 +0,0 @@ -#pragma once - -#include -#include -#include "utils.hpp" - -namespace aoc2019 { - template - class Point : public std::array { - public: - constexpr Point& operator +=(Point other) { - for (std::size_t i = 0; i < L; ++i) { - (*this)[i] += other[i]; - } - return *this; - } - - constexpr Point operator+(Point other) const { - auto result = *this; - result += other; - - return result; - } - - constexpr Point& operator -=(Point other) { - for (std::size_t i = 0; i < L; ++i) { - (*this)[i] -= other[i]; - } - - return *this; - } - - constexpr Point operator-(Point other) const { - auto result = *this; - result -= other; - - return result; - } - - constexpr T l1() const { - T result = 0; - for (auto e : *this) { - result += std::abs(e); - } - - return result; - } - }; - - template - std::pair, Point> bounding_box(const std::unordered_map, Ignored> &data) { - Point lower, upper; - std::fill(lower.begin(), lower.end(), std::numeric_limits::max()); - std::fill(upper.begin(), upper.end(), std::numeric_limits::min()); - - for (auto &entry : data) { - for (int i = 0; i < N; ++i) { - lower[i] = std::min(entry.first[i], lower[i]); - upper[i] = std::max(entry.first[i], upper[i]); - } - } - - return {lower, upper}; - } -} - -namespace std { - // Make point usable with unordered collections. - template struct hash> { - size_t operator()(const aoc2019::Point &o) const { - size_t seed = 0; - for (auto i : o) { - aoc2019::combine_hash(seed, i); - } - return seed; - } - }; -} diff --git a/2019/src/runner.cpp b/2019/src/runner.cpp deleted file mode 100644 index a640346..0000000 --- a/2019/src/runner.cpp +++ /dev/null @@ -1,135 +0,0 @@ -#include "implementations.hpp" -#include -#include -#include -#include -#include -#include - -struct AoCOptions { - aoc2019::solution_t implementation; - bool run_timer; - std::optional input_file; -}; - -static AoCOptions parse_options(const int argc, const char* argv[]) { - using namespace std::literals; - AoCOptions options{}; - - auto show_help = [argv] (int exit_status = 0) { - std::cerr << "Usage: " << argv[0] << " [--timer|-t] [--part2|-2] [--help|-h] DAY\n" - << "\t--timer|-t: print execution time\n" - << "\t--input ARG|-fARG: use given input file as puzzle input" - << "\t--part2|-2: run part 2\n" - << "\t --help|-h: show this message\n"; - std::exit(exit_status); - }; - - int day = -1; - bool part2 = false; - - // Here follows a manual implementation of getopt, since getopt doesn't work on windows… - for (int i = 1; i < argc; ++i) { - std::string_view arg(argv[i]); - if (arg[0] == '-') { - // Handle flag arguments - if (arg[1] != '-') { - // Shorthand flags - for (int j = 1; j < arg.size(); ++j) { - switch (arg[j]) { - case '2': - part2 = true; - break; - - case 't': - options.run_timer = true; - break; - - case 'h': - show_help(); - break; - - case 'f': - if (j == arg.size() - 1) { - if (i == argc - 1) { - std::cerr << "Option -f requires an argument."; - show_help(1); - } else { - options.input_file = std::ifstream(argv[i + 1]); - ++i; - } - } else { - options.input_file = std::ifstream(std::string(arg.substr(j))); - j = arg.size(); - } - break; - - default: - std::cerr << "Unknown flag '" << arg[j] << "'.\n\n"; - show_help(1); - } - } - } else { - // Handle long form versions - if (arg == "--timer"sv) { - part2 = true; - } else if (arg == "--timer"sv) { - options.run_timer = true; - } else if (arg == "--help"sv) { - show_help(); - } else if (arg == "--input"sv) { - if (i == argc - 1) { - std::cerr << "Option -f requires an argument."; - show_help(1); - } else { - options.input_file = std::ifstream(argv[i + 1]); - ++i; - } - } else { - show_help(1); - } - } - } else { - if (day != -1) { - // Double date specification, bail. - show_help(1); - } - - // Try to parse the date number - if (auto res = std::from_chars(arg.data(), arg.data() + arg.size(), day); res.ec != std::errc()) { - auto error_code = std::make_error_code(res.ec); - std::cerr << error_code.message() << "\n\n"; - show_help(1); - } - } - } - - if (day == -1) { - std::cerr << "Argument DAY is required.\n\n"; - show_help(1); - } else if (day < 1 || day > 25) { - std::cerr << "Invalid day. Valid range: [1, 25]\n"; - show_help(1); - } - - options.implementation = aoc2019::get_implementation(day, part2); - - return options; -} - -int main(int argc, const char *argv[]) { - auto options = parse_options(argc, argv); - - if (options.implementation != nullptr) { - const auto start = std::chrono::high_resolution_clock::now(); - options.implementation(options.input_file ? *options.input_file : std::cin, std::cout); - if (options.run_timer) { - const std::chrono::duration duration = std::chrono::high_resolution_clock::now() - start; - std::cerr << "Time taken: " << duration.count() << "s\n"; - } - return 0; - } else { - std::cerr << "Unimplemented.\n"; - return 1; - } -} diff --git a/2019/src/utils.cpp b/2019/src/utils.cpp deleted file mode 100644 index a037303..0000000 --- a/2019/src/utils.cpp +++ /dev/null @@ -1,191 +0,0 @@ -#include -#include "utils.hpp" - -std::string_view aoc2019::strtok(std::string_view &str, char token) { - auto next_delim = str.find(token); - auto next = str.substr(0, next_delim); - if (next_delim == std::string_view::npos) { - str = {}; - } else { - str = str.substr(next_delim + 1); - } - return next; -} - -std::deque aoc2019::run_intcode(std::vector program, std::deque inputs) { - std::deque outputs; - IntCodeComputer computer(std::move(program), std::move(inputs)); - computer.connectOutput(outputs); - - computer.run(); - - return outputs; -} - -aoc2019::IntCodeComputer::value_t &aoc2019::IntCodeComputer::interpret_value(int pos) { - value_t immediate; - switch (pos) { - case 1: - immediate = program[ip] / 100 % 10; - break; - case 2: - immediate = program[ip] / 1000 % 10; - break; - - case 3: - immediate = program[ip] / 10000 % 10; - break; - - default: - throw std::out_of_range("Invalid position"); - } - - value_t index; - - switch (immediate) { - case 0: - index = program[ip + pos]; - break; - - case 1: - index = ip + pos; - break; - - case 2: - index = program[ip + pos] + relative; - break; - - default: - throw std::out_of_range("Invalid mode"); - } - - if (program.size() <= index) { - program.resize(index + 1); - } - - return program[index]; -} - -void aoc2019::IntCodeComputer::connectOutput(aoc2019::IntCodeComputer &computer) { - outputSink = &computer.inputs; -} - -void aoc2019::IntCodeComputer::connectOutput(std::deque &sink) { - outputSink = &sink; -} - -bool aoc2019::IntCodeComputer::isTerminated() const { - return halted; -} - -const std::deque &aoc2019::IntCodeComputer::currentInputs() const { - return inputs; -} - -std::vector aoc2019::IntCodeComputer::read_intcode(std::istream &input) { - std::vector program; - for (value_t current; input >> current; input.ignore()) { - program.push_back(current); - } - - return program; -} - -void aoc2019::IntCodeComputer::run() { - while (ip < program.size()) { - switch (program[ip] % 100) { - case 1: - interpret_value(3) = interpret_value(1) + interpret_value(2); - ip += 4; - break; - - case 2: - interpret_value(3) = interpret_value(1) * interpret_value(2); - ip += 4; - break; - - case 3: - if (inputs.empty()) { - return; - } - - interpret_value(1) = inputs.front(); - inputs.pop_front(); - ip += 2; - break; - - case 4: - outputSink->push_back(interpret_value(1)); - ip += 2; - break; - - case 5: // Jump if non-zero - if (interpret_value(1)) { - ip = interpret_value(2); - } else { - ip += 3; - } - break; - - case 6: // Jump if zero - if (!interpret_value(1)) { - ip = interpret_value(2); - } else { - ip += 3; - } - break; - - case 7: // less than - interpret_value(3) = interpret_value(1) < interpret_value(2); - ip += 4; - break; - - case 8: // equality - interpret_value(3) = interpret_value(1) == interpret_value(2) ? 1 : 0; - ip += 4; - break; - - case 9: - relative += interpret_value(1); - ip += 2; - break; - - case 99: - halted = true; - return; - - default: - char buffer[30]; - std::snprintf(buffer, sizeof(buffer), "Invalid opcode: %d", program[ip]); - - throw std::domain_error(buffer); - } - } -} - -aoc2019::IntCodeComputer::IntCodeComputer(std::vector program, std::deque initial_inputs) : - program{std::move(program)}, inputs{std::move(initial_inputs)} { -} - - -aoc2019::IntCodeComputer::IntCodeComputer(std::istream &program_stream, std::deque initial_inputs) : - program(read_intcode(program_stream)), inputs(std::move(initial_inputs)) { -} - -void aoc2019::IntCodeComputer::sendInput(aoc2019::IntCodeComputer::value_t input) { - inputs.push_back(input); -} - -aoc2019::IntCodeComputer::value_t &aoc2019::IntCodeComputer::operator[](std::size_t index) { - return program[index]; -} - -const aoc2019::IntCodeComputer::value_t &aoc2019::IntCodeComputer::operator[](std::size_t index) const { - return program[index]; -} - -void aoc2019::IntCodeComputer::sendInputs(std::string_view str) { - for (char c : str) { - sendInput(c); - } -} diff --git a/2019/src/utils.hpp b/2019/src/utils.hpp deleted file mode 100644 index c339813..0000000 --- a/2019/src/utils.hpp +++ /dev/null @@ -1,123 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include -#include - -namespace aoc2019 { - - template - inline std::from_chars_result from_chars(std::string_view str, T &value) { - return std::from_chars(str.data(), str.data() + str.size(), value); - } - - template - void combine_hash(std::size_t &seed, const T &o) { - // Algorithm taken from boost::combine_hash. - std::hash hash{}; - seed ^= hash(o) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - } - - template - std::istream &read_line_numbers_and_garbage(std::istream &input, OutputIt output) { - ValueType v; - char c; - while (input && (c = input.peek()) != '\n') { - if (c == '-' || std::isdigit(c)) { - input >> v; - *output = v; - ++output; - } else { - input.ignore(); - } - } - - input.get(); - - return input; - } - - std::string_view strtok(std::string_view &str, char token = ','); - - std::deque run_intcode(std::vector program, std::deque inputs = {}); - - template - std::vector topological_sort(const std::unordered_map> &edge_list) { - std::unordered_map incoming_edges; - - for (auto &entry : edge_list) { - // Ensure entry for parent exist - incoming_edges[entry.first] += 0; - - for (auto &node : entry.second) { - incoming_edges[node]++; - } - } - - std::vector order; - std::deque childless; - - for (auto &entry : incoming_edges) { - if (!entry.second) { - childless.push_back(entry.first); - } - } - - while (!childless.empty()) { - auto current = childless.front(); - childless.pop_front(); - order.emplace_back(current); - - if (auto it = edge_list.find(current); it != edge_list.end()) { - for (const auto &parent : it->second) { - if (--incoming_edges[parent] == 0) { - childless.push_back(parent); - } - } - } - } - - if (order.size() != incoming_edges.size()) { - throw std::domain_error("Not a DAG."); - } - - return order; - } - - class IntCodeComputer { - public: - typedef std::int64_t value_t; - - explicit IntCodeComputer(std::vector program, std::deque initial_inputs = {}); - explicit IntCodeComputer(std::istream &program_stream, std::deque initial_inputs = {}); - - void run(); - void connectOutput(IntCodeComputer &computer); - void connectOutput(std::deque &sink); - void sendInput(value_t input); - - void sendInputs(std::string_view str); - - [[nodiscard]] bool isTerminated() const; - - [[nodiscard]] const std::deque ¤tInputs() const; - - value_t &operator[](std::size_t index); - const value_t &operator[](std::size_t index) const; - - static std::vector read_intcode(std::istream &input); - - private: - std::vector program; - std::deque inputs = {}; - std::deque *outputSink = nullptr; - int ip = 0; - int relative = 0; - bool halted = false; - - [[nodiscard]] value_t &interpret_value(int pos); - }; -} diff --git a/2019/tests/samples/.gitkeep b/2019/tests/samples/.gitkeep deleted file mode 100644 index 8b13789..0000000 --- a/2019/tests/samples/.gitkeep +++ /dev/null @@ -1 +0,0 @@ - diff --git a/2019/tests/samples/01-1-1.in b/2019/tests/samples/01-1-1.in deleted file mode 100644 index ff999fc..0000000 --- a/2019/tests/samples/01-1-1.in +++ /dev/null @@ -1 +0,0 @@ -100756 diff --git a/2019/tests/samples/01-1-1.out b/2019/tests/samples/01-1-1.out deleted file mode 100644 index 4407060..0000000 --- a/2019/tests/samples/01-1-1.out +++ /dev/null @@ -1 +0,0 @@ -33583 diff --git a/2019/tests/samples/03-1-1.in b/2019/tests/samples/03-1-1.in deleted file mode 100644 index 620a05e..0000000 --- a/2019/tests/samples/03-1-1.in +++ /dev/null @@ -1,2 +0,0 @@ -R75,D30,R83,U83,L12,D49,R71,U7,L72 -U62,R66,U55,R34,D71,R55,D58,R83 diff --git a/2019/tests/samples/03-1-1.out b/2019/tests/samples/03-1-1.out deleted file mode 100644 index 3f7d191..0000000 --- a/2019/tests/samples/03-1-1.out +++ /dev/null @@ -1 +0,0 @@ -159 diff --git a/2019/tests/samples/03-1-2.in b/2019/tests/samples/03-1-2.in deleted file mode 100644 index 4f3a2a4..0000000 --- a/2019/tests/samples/03-1-2.in +++ /dev/null @@ -1,2 +0,0 @@ -R98,U47,R26,D63,R33,U87,L62,D20,R33,U53,R51 -U98,R91,D20,R16,D67,R40,U7,R15,U6,R7 diff --git a/2019/tests/samples/03-1-2.out b/2019/tests/samples/03-1-2.out deleted file mode 100644 index c8b255f..0000000 --- a/2019/tests/samples/03-1-2.out +++ /dev/null @@ -1 +0,0 @@ -135 diff --git a/2019/tests/samples/03-1-3.in b/2019/tests/samples/03-1-3.in deleted file mode 100644 index 73b95a1..0000000 --- a/2019/tests/samples/03-1-3.in +++ /dev/null @@ -1,2 +0,0 @@ -R8,U5,L5,D3 -U7,R6,D4,L4 diff --git a/2019/tests/samples/03-1-3.out b/2019/tests/samples/03-1-3.out deleted file mode 100644 index 1e8b314..0000000 --- a/2019/tests/samples/03-1-3.out +++ /dev/null @@ -1 +0,0 @@ -6 diff --git a/2019/tests/samples/03-2-1.in b/2019/tests/samples/03-2-1.in deleted file mode 120000 index 0a78c00..0000000 --- a/2019/tests/samples/03-2-1.in +++ /dev/null @@ -1 +0,0 @@ -03-1-1.in \ No newline at end of file diff --git a/2019/tests/samples/03-2-1.out b/2019/tests/samples/03-2-1.out deleted file mode 100644 index 502380c..0000000 --- a/2019/tests/samples/03-2-1.out +++ /dev/null @@ -1 +0,0 @@ -610 diff --git a/2019/tests/samples/03-2-2.in b/2019/tests/samples/03-2-2.in deleted file mode 120000 index 7594846..0000000 --- a/2019/tests/samples/03-2-2.in +++ /dev/null @@ -1 +0,0 @@ -03-1-2.in \ No newline at end of file diff --git a/2019/tests/samples/03-2-2.out b/2019/tests/samples/03-2-2.out deleted file mode 100644 index 17e344e..0000000 --- a/2019/tests/samples/03-2-2.out +++ /dev/null @@ -1 +0,0 @@ -410 diff --git a/2019/tests/samples/03-2-3.in b/2019/tests/samples/03-2-3.in deleted file mode 120000 index 73744a7..0000000 --- a/2019/tests/samples/03-2-3.in +++ /dev/null @@ -1 +0,0 @@ -03-1-3.in \ No newline at end of file diff --git a/2019/tests/samples/03-2-3.out b/2019/tests/samples/03-2-3.out deleted file mode 100644 index 64bb6b7..0000000 --- a/2019/tests/samples/03-2-3.out +++ /dev/null @@ -1 +0,0 @@ -30 diff --git a/2019/tests/samples/06-1-1.in b/2019/tests/samples/06-1-1.in deleted file mode 100644 index 183242d..0000000 --- a/2019/tests/samples/06-1-1.in +++ /dev/null @@ -1,11 +0,0 @@ -COM)B -B)C -C)D -D)E -E)F -B)G -G)H -D)I -E)J -J)K -K)L diff --git a/2019/tests/samples/06-1-1.out b/2019/tests/samples/06-1-1.out deleted file mode 100644 index d81cc07..0000000 --- a/2019/tests/samples/06-1-1.out +++ /dev/null @@ -1 +0,0 @@ -42 diff --git a/2019/tests/samples/06-2-1.in b/2019/tests/samples/06-2-1.in deleted file mode 100644 index a1007c6..0000000 --- a/2019/tests/samples/06-2-1.in +++ /dev/null @@ -1,13 +0,0 @@ -COM)B -B)C -C)D -D)E -E)F -B)G -G)H -D)I -E)J -J)K -K)L -K)YOU -I)SAN diff --git a/2019/tests/samples/06-2-1.out b/2019/tests/samples/06-2-1.out deleted file mode 100644 index b8626c4..0000000 --- a/2019/tests/samples/06-2-1.out +++ /dev/null @@ -1 +0,0 @@ -4 diff --git a/2019/tests/samples/07-1-1.in b/2019/tests/samples/07-1-1.in deleted file mode 100644 index e626457..0000000 --- a/2019/tests/samples/07-1-1.in +++ /dev/null @@ -1 +0,0 @@ -3,15,3,16,1002,16,10,16,1,16,15,15,4,15,99,0,0 diff --git a/2019/tests/samples/07-1-1.out b/2019/tests/samples/07-1-1.out deleted file mode 100644 index d977160..0000000 --- a/2019/tests/samples/07-1-1.out +++ /dev/null @@ -1 +0,0 @@ -43210 diff --git a/2019/tests/samples/07-1-2.in b/2019/tests/samples/07-1-2.in deleted file mode 100644 index 99ab27e..0000000 --- a/2019/tests/samples/07-1-2.in +++ /dev/null @@ -1,2 +0,0 @@ -3,23,3,24,1002,24,10,24,1002,23,-1,23, -101,5,23,23,1,24,23,23,4,23,99,0,0 diff --git a/2019/tests/samples/07-1-2.out b/2019/tests/samples/07-1-2.out deleted file mode 100644 index 67c0579..0000000 --- a/2019/tests/samples/07-1-2.out +++ /dev/null @@ -1 +0,0 @@ -54321 diff --git a/2019/tests/samples/07-1-3.in b/2019/tests/samples/07-1-3.in deleted file mode 100644 index 6f8a3b2..0000000 --- a/2019/tests/samples/07-1-3.in +++ /dev/null @@ -1,2 +0,0 @@ -3,31,3,32,1002,32,10,32,1001,31,-2,31,1007,31,0,33, -1002,33,7,33,1,33,31,31,1,32,31,31,4,31,99,0,0,0 diff --git a/2019/tests/samples/07-1-3.out b/2019/tests/samples/07-1-3.out deleted file mode 100644 index 8c1ca06..0000000 --- a/2019/tests/samples/07-1-3.out +++ /dev/null @@ -1 +0,0 @@ -65210 diff --git a/2019/tests/samples/07-2-1.in b/2019/tests/samples/07-2-1.in deleted file mode 100644 index 3778360..0000000 --- a/2019/tests/samples/07-2-1.in +++ /dev/null @@ -1,2 +0,0 @@ -3,26,1001,26,-4,26,3,27,1002,27,2,27,1,27,26, -27,4,27,1001,28,-1,28,1005,28,6,99,0,0,5 diff --git a/2019/tests/samples/07-2-1.out b/2019/tests/samples/07-2-1.out deleted file mode 100644 index 76bf43f..0000000 --- a/2019/tests/samples/07-2-1.out +++ /dev/null @@ -1 +0,0 @@ -139629729 diff --git a/2019/tests/samples/07-2-2.in b/2019/tests/samples/07-2-2.in deleted file mode 100644 index 6aa329f..0000000 --- a/2019/tests/samples/07-2-2.in +++ /dev/null @@ -1,3 +0,0 @@ -3,52,1001,52,-5,52,3,53,1,52,56,54,1007,54,5,55,1005,55,26,1001,54, --5,54,1105,1,12,1,53,54,53,1008,54,0,55,1001,55,1,55,2,53,55,53,4, -53,1001,56,-1,56,1005,56,6,99,0,0,0,0,10 diff --git a/2019/tests/samples/07-2-2.out b/2019/tests/samples/07-2-2.out deleted file mode 100644 index 1c14ce2..0000000 --- a/2019/tests/samples/07-2-2.out +++ /dev/null @@ -1 +0,0 @@ -18216 diff --git a/2019/tests/samples/10-1-1.in b/2019/tests/samples/10-1-1.in deleted file mode 100644 index 737ae7f..0000000 --- a/2019/tests/samples/10-1-1.in +++ /dev/null @@ -1,5 +0,0 @@ -.#..# -..... -##### -....# -...## diff --git a/2019/tests/samples/10-1-1.out b/2019/tests/samples/10-1-1.out deleted file mode 100644 index 45a4fb7..0000000 --- a/2019/tests/samples/10-1-1.out +++ /dev/null @@ -1 +0,0 @@ -8 diff --git a/2019/tests/samples/10-1-2.in b/2019/tests/samples/10-1-2.in deleted file mode 100644 index 987698f..0000000 --- a/2019/tests/samples/10-1-2.in +++ /dev/null @@ -1,10 +0,0 @@ -......#.#. -#..#.#.... -..#######. -.#.#.###.. -.#..#..... -..#....#.# -#..#....#. -.##.#..### -##...#..#. -.#....#### diff --git a/2019/tests/samples/10-1-2.out b/2019/tests/samples/10-1-2.out deleted file mode 100644 index bb95160..0000000 --- a/2019/tests/samples/10-1-2.out +++ /dev/null @@ -1 +0,0 @@ -33 diff --git a/2019/tests/samples/10-1-3.in b/2019/tests/samples/10-1-3.in deleted file mode 100644 index e28e424..0000000 --- a/2019/tests/samples/10-1-3.in +++ /dev/null @@ -1,10 +0,0 @@ -#.#...#.#. -.###....#. -.#....#... -##.#.#.#.# -....#.#.#. -.##..###.# -..#...##.. -..##....## -......#... -.####.###. diff --git a/2019/tests/samples/10-1-3.out b/2019/tests/samples/10-1-3.out deleted file mode 100644 index 8f92bfd..0000000 --- a/2019/tests/samples/10-1-3.out +++ /dev/null @@ -1 +0,0 @@ -35 diff --git a/2019/tests/samples/10-1-4.in b/2019/tests/samples/10-1-4.in deleted file mode 100644 index af5b6e9..0000000 --- a/2019/tests/samples/10-1-4.in +++ /dev/null @@ -1,10 +0,0 @@ -.#..#..### -####.###.# -....###.#. -..###.##.# -##.##.#.#. -....###..# -..#.#..#.# -#..#.#.### -.##...##.# -.....#.#.. diff --git a/2019/tests/samples/10-1-4.out b/2019/tests/samples/10-1-4.out deleted file mode 100644 index 87523dd..0000000 --- a/2019/tests/samples/10-1-4.out +++ /dev/null @@ -1 +0,0 @@ -41 diff --git a/2019/tests/samples/10-1-5.in b/2019/tests/samples/10-1-5.in deleted file mode 100644 index 33437ba..0000000 --- a/2019/tests/samples/10-1-5.in +++ /dev/null @@ -1,20 +0,0 @@ -.#..##.###...####### -##.############..##. -.#.######.########.# -.###.#######.####.#. -#####.##.#.##.###.## -..#####..#.######### -#################### -#.####....###.#.#.## -##.################# -#####.##.###..####.. -..######..##.####### -####.##.####...##..# -.#####..#.######.### -##...#.##########... -#.##########.####### -.####.#.###.###.#.## -....##.##.###..##### -.#.#.###########.### -#.#.#.#####.####.### -###.##.####.##.#..## diff --git a/2019/tests/samples/10-1-5.out b/2019/tests/samples/10-1-5.out deleted file mode 100644 index cd7da05..0000000 --- a/2019/tests/samples/10-1-5.out +++ /dev/null @@ -1 +0,0 @@ -210 diff --git a/2019/tests/samples/12-2-1.in b/2019/tests/samples/12-2-1.in deleted file mode 100644 index 89cc805..0000000 --- a/2019/tests/samples/12-2-1.in +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/2019/tests/samples/12-2-1.out b/2019/tests/samples/12-2-1.out deleted file mode 100644 index f3f2632..0000000 --- a/2019/tests/samples/12-2-1.out +++ /dev/null @@ -1 +0,0 @@ -2772 diff --git a/2019/tests/samples/12-2-2.in b/2019/tests/samples/12-2-2.in deleted file mode 100644 index 1078293..0000000 --- a/2019/tests/samples/12-2-2.in +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/2019/tests/samples/12-2-2.out b/2019/tests/samples/12-2-2.out deleted file mode 100644 index f84ffdb..0000000 --- a/2019/tests/samples/12-2-2.out +++ /dev/null @@ -1 +0,0 @@ -4686774924 diff --git a/2019/tests/samples/14-1-1.in b/2019/tests/samples/14-1-1.in deleted file mode 100644 index 65ad5cc..0000000 --- a/2019/tests/samples/14-1-1.in +++ /dev/null @@ -1,6 +0,0 @@ -10 ORE => 10 A -1 ORE => 1 B -7 A, 1 B => 1 C -7 A, 1 C => 1 D -7 A, 1 D => 1 E -7 A, 1 E => 1 FUEL diff --git a/2019/tests/samples/14-1-1.out b/2019/tests/samples/14-1-1.out deleted file mode 100644 index e85087a..0000000 --- a/2019/tests/samples/14-1-1.out +++ /dev/null @@ -1 +0,0 @@ -31 diff --git a/2019/tests/samples/14-1-2.in b/2019/tests/samples/14-1-2.in deleted file mode 100644 index 85c4b1e..0000000 --- a/2019/tests/samples/14-1-2.in +++ /dev/null @@ -1,7 +0,0 @@ -9 ORE => 2 A -8 ORE => 3 B -7 ORE => 5 C -3 A, 4 B => 1 AB -5 B, 7 C => 1 BC -4 C, 1 A => 1 CA -2 AB, 3 BC, 4 CA => 1 FUEL diff --git a/2019/tests/samples/14-1-2.out b/2019/tests/samples/14-1-2.out deleted file mode 100644 index 9e42f3e..0000000 --- a/2019/tests/samples/14-1-2.out +++ /dev/null @@ -1 +0,0 @@ -165 diff --git a/2019/tests/samples/14-1-3.in b/2019/tests/samples/14-1-3.in deleted file mode 100644 index 4d6b9f0..0000000 --- a/2019/tests/samples/14-1-3.in +++ /dev/null @@ -1,9 +0,0 @@ -157 ORE => 5 NZVS -165 ORE => 6 DCFZ -44 XJWVT, 5 KHKGT, 1 QDVJ, 29 NZVS, 9 GPVTF, 48 HKGWZ => 1 FUEL -12 HKGWZ, 1 GPVTF, 8 PSHF => 9 QDVJ -179 ORE => 7 PSHF -177 ORE => 5 HKGWZ -7 DCFZ, 7 PSHF => 2 XJWVT -165 ORE => 2 GPVTF -3 DCFZ, 7 NZVS, 5 HKGWZ, 10 PSHF => 8 KHKGT diff --git a/2019/tests/samples/14-1-3.out b/2019/tests/samples/14-1-3.out deleted file mode 100644 index ccb0cfe..0000000 --- a/2019/tests/samples/14-1-3.out +++ /dev/null @@ -1 +0,0 @@ -13312 diff --git a/2019/tests/samples/14-1-4.in b/2019/tests/samples/14-1-4.in deleted file mode 100644 index c670978..0000000 --- a/2019/tests/samples/14-1-4.in +++ /dev/null @@ -1,12 +0,0 @@ -2 VPVL, 7 FWMGM, 2 CXFTF, 11 MNCFX => 1 STKFG -17 NVRVD, 3 JNWZP => 8 VPVL -53 STKFG, 6 MNCFX, 46 VJHF, 81 HVMC, 68 CXFTF, 25 GNMV => 1 FUEL -22 VJHF, 37 MNCFX => 5 FWMGM -139 ORE => 4 NVRVD -144 ORE => 7 JNWZP -5 MNCFX, 7 RFSQX, 2 FWMGM, 2 VPVL, 19 CXFTF => 3 HVMC -5 VJHF, 7 MNCFX, 9 VPVL, 37 CXFTF => 6 GNMV -145 ORE => 6 MNCFX -1 NVRVD => 8 CXFTF -1 VJHF, 6 MNCFX => 4 RFSQX -176 ORE => 6 VJHF diff --git a/2019/tests/samples/14-1-4.out b/2019/tests/samples/14-1-4.out deleted file mode 100644 index cb19a6c..0000000 --- a/2019/tests/samples/14-1-4.out +++ /dev/null @@ -1 +0,0 @@ -180697 diff --git a/2019/tests/samples/14-1-5.in b/2019/tests/samples/14-1-5.in deleted file mode 100644 index a5ca2c3..0000000 --- a/2019/tests/samples/14-1-5.in +++ /dev/null @@ -1,17 +0,0 @@ -171 ORE => 8 CNZTR -7 ZLQW, 3 BMBT, 9 XCVML, 26 XMNCP, 1 WPTQ, 2 MZWV, 1 RJRHP => 4 PLWSL -114 ORE => 4 BHXH -14 VRPVC => 6 BMBT -6 BHXH, 18 KTJDG, 12 WPTQ, 7 PLWSL, 31 FHTLT, 37 ZDVW => 1 FUEL -6 WPTQ, 2 BMBT, 8 ZLQW, 18 KTJDG, 1 XMNCP, 6 MZWV, 1 RJRHP => 6 FHTLT -15 XDBXC, 2 LTCX, 1 VRPVC => 6 ZLQW -13 WPTQ, 10 LTCX, 3 RJRHP, 14 XMNCP, 2 MZWV, 1 ZLQW => 1 ZDVW -5 BMBT => 4 WPTQ -189 ORE => 9 KTJDG -1 MZWV, 17 XDBXC, 3 XCVML => 2 XMNCP -12 VRPVC, 27 CNZTR => 2 XDBXC -15 KTJDG, 12 BHXH => 5 XCVML -3 BHXH, 2 VRPVC => 7 MZWV -121 ORE => 7 VRPVC -7 XCVML => 6 RJRHP -5 BHXH, 4 VRPVC => 5 LTCX diff --git a/2019/tests/samples/14-1-5.out b/2019/tests/samples/14-1-5.out deleted file mode 100644 index b65e868..0000000 --- a/2019/tests/samples/14-1-5.out +++ /dev/null @@ -1 +0,0 @@ -2210736 diff --git a/2019/tests/samples/14-2-1.in b/2019/tests/samples/14-2-1.in deleted file mode 120000 index e5a7725..0000000 --- a/2019/tests/samples/14-2-1.in +++ /dev/null @@ -1 +0,0 @@ -14-1-3.in \ No newline at end of file diff --git a/2019/tests/samples/14-2-1.out b/2019/tests/samples/14-2-1.out deleted file mode 100644 index 421714d..0000000 --- a/2019/tests/samples/14-2-1.out +++ /dev/null @@ -1 +0,0 @@ -82892753 diff --git a/2019/tests/samples/14-2-2.in b/2019/tests/samples/14-2-2.in deleted file mode 120000 index 78b977b..0000000 --- a/2019/tests/samples/14-2-2.in +++ /dev/null @@ -1 +0,0 @@ -14-1-4.in \ No newline at end of file diff --git a/2019/tests/samples/14-2-2.out b/2019/tests/samples/14-2-2.out deleted file mode 100644 index c55239b..0000000 --- a/2019/tests/samples/14-2-2.out +++ /dev/null @@ -1 +0,0 @@ -5586022 diff --git a/2019/tests/samples/14-2-3.in b/2019/tests/samples/14-2-3.in deleted file mode 120000 index 7e9ed9d..0000000 --- a/2019/tests/samples/14-2-3.in +++ /dev/null @@ -1 +0,0 @@ -14-1-5.in \ No newline at end of file diff --git a/2019/tests/samples/14-2-3.out b/2019/tests/samples/14-2-3.out deleted file mode 100644 index 1a5d12f..0000000 --- a/2019/tests/samples/14-2-3.out +++ /dev/null @@ -1 +0,0 @@ -460664 diff --git a/2019/tests/samples/16-1-1.in b/2019/tests/samples/16-1-1.in deleted file mode 100644 index a0d6069..0000000 --- a/2019/tests/samples/16-1-1.in +++ /dev/null @@ -1 +0,0 @@ -80871224585914546619083218645595 diff --git a/2019/tests/samples/16-1-1.out b/2019/tests/samples/16-1-1.out deleted file mode 100644 index e3a8042..0000000 --- a/2019/tests/samples/16-1-1.out +++ /dev/null @@ -1 +0,0 @@ -24176176 diff --git a/2019/tests/samples/16-1-2.in b/2019/tests/samples/16-1-2.in deleted file mode 100644 index e62b53a..0000000 --- a/2019/tests/samples/16-1-2.in +++ /dev/null @@ -1 +0,0 @@ -19617804207202209144916044189917 diff --git a/2019/tests/samples/16-1-2.out b/2019/tests/samples/16-1-2.out deleted file mode 100644 index a8ff9e0..0000000 --- a/2019/tests/samples/16-1-2.out +++ /dev/null @@ -1 +0,0 @@ -73745418 diff --git a/2019/tests/samples/16-1-3.in b/2019/tests/samples/16-1-3.in deleted file mode 100644 index fc400a2..0000000 --- a/2019/tests/samples/16-1-3.in +++ /dev/null @@ -1 +0,0 @@ -69317163492948606335995924319873 diff --git a/2019/tests/samples/16-1-3.out b/2019/tests/samples/16-1-3.out deleted file mode 100644 index 628d8a5..0000000 --- a/2019/tests/samples/16-1-3.out +++ /dev/null @@ -1 +0,0 @@ -52432133 diff --git a/2019/tests/samples/18-1-1.in b/2019/tests/samples/18-1-1.in deleted file mode 100644 index 33802e1..0000000 --- a/2019/tests/samples/18-1-1.in +++ /dev/null @@ -1,3 +0,0 @@ -######### -#b.A.@.a# -######### diff --git a/2019/tests/samples/18-1-1.out b/2019/tests/samples/18-1-1.out deleted file mode 100644 index 45a4fb7..0000000 --- a/2019/tests/samples/18-1-1.out +++ /dev/null @@ -1 +0,0 @@ -8 diff --git a/2019/tests/samples/18-1-2.in b/2019/tests/samples/18-1-2.in deleted file mode 100644 index af485bc..0000000 --- a/2019/tests/samples/18-1-2.in +++ /dev/null @@ -1,5 +0,0 @@ -######################## -#f.D.E.e.C.b.A.@.a.B.c.# -######################.# -#d.....................# -######################## diff --git a/2019/tests/samples/18-1-2.out b/2019/tests/samples/18-1-2.out deleted file mode 100644 index 8cf5c1a..0000000 --- a/2019/tests/samples/18-1-2.out +++ /dev/null @@ -1 +0,0 @@ -86 diff --git a/2019/tests/samples/18-1-3.in b/2019/tests/samples/18-1-3.in deleted file mode 100644 index b650235..0000000 --- a/2019/tests/samples/18-1-3.in +++ /dev/null @@ -1,5 +0,0 @@ -######################## -#...............b.C.D.f# -#.###################### -#.....@.a.B.c.d.A.e.F.g# -######################## diff --git a/2019/tests/samples/18-1-3.out b/2019/tests/samples/18-1-3.out deleted file mode 100644 index 94361d4..0000000 --- a/2019/tests/samples/18-1-3.out +++ /dev/null @@ -1 +0,0 @@ -132 diff --git a/2019/tests/samples/18-1-4.in b/2019/tests/samples/18-1-4.in deleted file mode 100644 index d5d888b..0000000 --- a/2019/tests/samples/18-1-4.in +++ /dev/null @@ -1,9 +0,0 @@ -################# -#i.G..c...e..H.p# -########.######## -#j.A..b...f..D.o# -########@######## -#k.E..a...g..B.n# -########.######## -#l.F..d...h..C.m# -################# diff --git a/2019/tests/samples/18-1-4.out b/2019/tests/samples/18-1-4.out deleted file mode 100644 index 7296f25..0000000 --- a/2019/tests/samples/18-1-4.out +++ /dev/null @@ -1 +0,0 @@ -136 diff --git a/2019/tests/samples/18-1-5.in b/2019/tests/samples/18-1-5.in deleted file mode 100644 index ee6598e..0000000 --- a/2019/tests/samples/18-1-5.in +++ /dev/null @@ -1,6 +0,0 @@ -######################## -#@..............ac.GI.b# -###d#e#f################ -###A#B#C################ -###g#h#i################ -######################## diff --git a/2019/tests/samples/18-1-5.out b/2019/tests/samples/18-1-5.out deleted file mode 100644 index d88e313..0000000 --- a/2019/tests/samples/18-1-5.out +++ /dev/null @@ -1 +0,0 @@ -81 diff --git a/2019/tests/samples/18-2-1.in b/2019/tests/samples/18-2-1.in deleted file mode 100644 index a2cfd7e..0000000 --- a/2019/tests/samples/18-2-1.in +++ /dev/null @@ -1,7 +0,0 @@ -############### -#d.ABC.#.....a# -######...###### -######.@.###### -######...###### -#b.....#.....c# -############### diff --git a/2019/tests/samples/18-2-1.out b/2019/tests/samples/18-2-1.out deleted file mode 100644 index a45fd52..0000000 --- a/2019/tests/samples/18-2-1.out +++ /dev/null @@ -1 +0,0 @@ -24 diff --git a/2019/tests/samples/20-1-1.in b/2019/tests/samples/20-1-1.in deleted file mode 100644 index 1e8d56f..0000000 --- a/2019/tests/samples/20-1-1.in +++ /dev/null @@ -1,19 +0,0 @@ - A - A - #######.######### - #######.........# - #######.#######.# - #######.#######.# - #######.#######.# - ##### B ###.# -BC...## C ###.# - ##.## ###.# - ##...DE F ###.# - ##### G ###.# - #########.#####.# -DE..#######...###.# - #.#########.###.# -FG..#########.....# - ###########.##### - Z - Z diff --git a/2019/tests/samples/20-1-1.out b/2019/tests/samples/20-1-1.out deleted file mode 100644 index 4099407..0000000 --- a/2019/tests/samples/20-1-1.out +++ /dev/null @@ -1 +0,0 @@ -23 diff --git a/2019/tests/samples/20-1-2.in b/2019/tests/samples/20-1-2.in deleted file mode 100644 index 6f61581..0000000 --- a/2019/tests/samples/20-1-2.in +++ /dev/null @@ -1,37 +0,0 @@ - A - A - #################.############# - #.#...#...................#.#.# - #.#.#.###.###.###.#########.#.# - #.#.#.......#...#.....#.#.#...# - #.#########.###.#####.#.#.###.# - #.............#.#.....#.......# - ###.###########.###.#####.#.#.# - #.....# A C #.#.#.# - ####### S P #####.# - #.#...# #......VT - #.#.#.# #.##### - #...#.# YN....#.# - #.###.# #####.# -DI....#.# #.....# - #####.# #.###.# -ZZ......# QG....#..AS - ###.### ####### -JO..#.#.# #.....# - #.#.#.# ###.#.# - #...#..DI BU....#..LF - #####.# #.##### -YN......# VT..#....QG - #.###.# #.###.# - #.#...# #.....# - ###.### J L J #.#.### - #.....# O F P #.#...# - #.###.#####.#.#####.#####.###.# - #...#.#.#...#.....#.....#.#...# - #.#####.###.###.#.#.#########.# - #...#.#.....#...#.#.#.#.....#.# - #.###.#####.###.###.#.#.####### - #.#.........#...#.............# - #########.###.###.############# - B J C - U P P diff --git a/2019/tests/samples/20-1-2.out b/2019/tests/samples/20-1-2.out deleted file mode 100644 index 8c61d23..0000000 --- a/2019/tests/samples/20-1-2.out +++ /dev/null @@ -1 +0,0 @@ -58 diff --git a/2019/tests/samples/20-2-2.in b/2019/tests/samples/20-2-2.in deleted file mode 100644 index d051133..0000000 --- a/2019/tests/samples/20-2-2.in +++ /dev/null @@ -1,37 +0,0 @@ - Z L X W C - Z P Q B K - ###########.#.#.#.#######.############### - #...#.......#.#.......#.#.......#.#.#...# - ###.#.#.#.#.#.#.#.###.#.#.#######.#.#.### - #.#...#.#.#...#.#.#...#...#...#.#.......# - #.###.#######.###.###.#.###.###.#.####### - #...#.......#.#...#...#.............#...# - #.#########.#######.#.#######.#######.### - #...#.# F R I Z #.#.#.# - #.###.# D E C H #.#.#.# - #.#...# #...#.# - #.###.# #.###.# - #.#....OA WB..#.#..ZH - #.###.# #.#.#.# -CJ......# #.....# - ####### ####### - #.#....CK #......IC - #.###.# #.###.# - #.....# #...#.# - ###.### #.#.#.# -XF....#.# RF..#.#.# - #####.# ####### - #......CJ NM..#...# - ###.#.# #.###.# -RE....#.# #......RF - ###.### X X L #.#.#.# - #.....# F Q P #.#.#.# - ###.###########.###.#######.#########.### - #.....#...#.....#.......#...#.....#.#...# - #####.#.###.#######.#######.###.###.#.#.# - #.......#.......#.#.#.#.#...#...#...#.#.# - #####.###.#####.#.#.#.#.###.###.#.###.### - #.......#.....#.#...#...............#...# - #############.#.#.###.################### - A O F N - A A D M diff --git a/2019/tests/samples/20-2-2.out b/2019/tests/samples/20-2-2.out deleted file mode 100644 index 4391a33..0000000 --- a/2019/tests/samples/20-2-2.out +++ /dev/null @@ -1 +0,0 @@ -396 diff --git a/2019/tests/samples/24-1-1.in b/2019/tests/samples/24-1-1.in deleted file mode 100644 index 704a112..0000000 --- a/2019/tests/samples/24-1-1.in +++ /dev/null @@ -1,5 +0,0 @@ -....# -#..#. -#..## -..#.. -#.... diff --git a/2019/tests/samples/24-1-1.out b/2019/tests/samples/24-1-1.out deleted file mode 100644 index 39f6036..0000000 --- a/2019/tests/samples/24-1-1.out +++ /dev/null @@ -1 +0,0 @@ -2129920 diff --git a/2019/tests/test_intcode.cpp b/2019/tests/test_intcode.cpp deleted file mode 100644 index c9adc85..0000000 --- a/2019/tests/test_intcode.cpp +++ /dev/null @@ -1,78 +0,0 @@ -#include -#include "utils.hpp" - -using aoc2019::run_intcode; -using aoc2019::IntCodeComputer; - -auto run_program(std::vector program, std::deque input) { - std::deque output; - IntCodeComputer computer(std::move(program), std::move(input)); - computer.connectOutput(output); - computer.run(); - return output; -} - -TEST(Intcode, TestReproduceInput) { - const std::vector program = {109, 1, 204, -1, 1001, 100, 1, 100, 1008, 100, 16, 101, 1006, 101, 0, 99}; - const std::deque expected(program.begin(), program.end()); - - ASSERT_EQ(expected, run_program(program, {})); -} - -TEST(Intcode, TestLargeMultiplication) { - const std::vector program = {1102, 34915192, 34915192, 7, 4, 7, 99, 0}; - - ASSERT_EQ(1219070632396864, run_program(program, {}).front()); -} - -TEST(Intcode, TestLargeNumber) { - const std::vector program = {104, 1125899906842624, 99}; - - ASSERT_EQ(1125899906842624, run_program(program, {}).front()); -} - -TEST(Intcode, TestPositionEquality) { - const std::vector program = {3, 9, 8, 9, 10, 9, 4, 9, 99, -1, 8}; - - ASSERT_EQ(1, run_program(program, {8}).front()); - ASSERT_EQ(0, run_program(program, {9}).front()); -} - -TEST(Intcode, TestPositionLess) { - const std::vector program = {3, 9, 7, 9, 10, 9, 4, 9, 99, -1, 8}; - - ASSERT_EQ(1, run_program(program, {7}).front()); - ASSERT_EQ(0, run_program(program, {9}).front()); -} - -TEST(Intcode, TestImmediateEquality) { - const std::vector program = {3, 3, 1108, -1, 8, 3, 4, 3, 99}; - - ASSERT_EQ(1, run_program(program, {8}).front()); - ASSERT_EQ(0, run_program(program, {9}).front()); -} - -TEST(Intcode, TestImmediateLess) { - const std::vector program = {3, 3, 1107, -1, 8, 3, 4, 3, 99}; - - ASSERT_EQ(1, run_program(program, {7}).front()); - ASSERT_EQ(0, run_program(program, {9}).front()); -} - -TEST(Intcode, TestComplicatedConditional) { - const std::vector program = {3, 21, 1008, 21, 8, 20, 1005, 20, 22, 107, 8, 21, 20, 1006, 20, 31, - 1106, 0, 36, 98, 0, 0, 1002, 21, 125, 20, 4, 20, 1105, 1, 46, 104, - 999, 1105, 1, 46, 1101, 1000, 1, 20, 4, 20, 1105, 1, 46, 98, 99}; - auto pcopy = program; - - auto output = run_intcode(pcopy, {7}); - ASSERT_EQ(999, output.front()); - - pcopy = program; - output = run_intcode(pcopy, {9}); - ASSERT_EQ(1001, output.front()); - - pcopy = program; - output = run_intcode(pcopy, {8}); - ASSERT_EQ(1000, output.front()); -} diff --git a/2019/tests/test_solutions.cpp b/2019/tests/test_solutions.cpp deleted file mode 100644 index ea870bc..0000000 --- a/2019/tests/test_solutions.cpp +++ /dev/null @@ -1,110 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include "implementations.hpp" - -class SolutionsTest : public testing::TestWithParam { -public: - static std::string nameInstantiatedTest(const testing::TestParamInfo ¶mInfo); - -protected: - std::string input_data = ""; - std::string output_data = ""; - aoc2019::solution_t implementation = nullptr; - - // Read input data - void SetUp() override; - -private: - static void readToString(const std::string &name, std::string &target); - - static std::tuple parseInputName(const std::string &name); -}; - -void SolutionsTest::SetUp() { - const auto input_name = GetParam(); - const auto output_name = input_name.substr(0, input_name.length() - 3) + ".out"; - - int day; - bool part2; - std::tie(day, part2, std::ignore) = parseInputName(input_name); - implementation = aoc2019::get_implementation(day, part2); - - readToString(input_name, input_data); - readToString(output_name, output_data); -} - -void SolutionsTest::readToString(const std::string &name, std::string &target) { - std::ifstream source(name); - - target.assign(std::istreambuf_iterator(source), - std::istreambuf_iterator()); -} - -std::tuple SolutionsTest::parseInputName(const std::string &name) { - const char *base_name = name.c_str(); - if (const auto last_slash = name.rfind('/'); last_slash != std::string::npos) { - base_name += last_slash + 1; - } - int day, part; - auto res = std::from_chars(base_name, base_name + 2, day); - assert(res.ec == std::errc()); - res = std::from_chars(base_name + 3, base_name + 4, part); - assert(res.ec == std::errc()); - - return {day, part == 2, std::string(base_name + 5, (const char*) std::strchr(base_name, '.'))}; -} - -std::string SolutionsTest::nameInstantiatedTest(const testing::TestParamInfo ¶mInfo) { - int day; - bool part2; - std::string sampleName; - - std::tie(day, part2, sampleName) = parseInputName(paramInfo.param); - - std::stringstream nameBuilder; - - nameBuilder << "Day" << day << "Part" << (part2 ? 2 : 1) << "Sample"; - - std::copy_if(sampleName.cbegin(), sampleName.cend(), std::ostream_iterator(nameBuilder), [](char c) { - return std::isalnum(c); - }); - - return nameBuilder.str(); -} - -TEST_P(SolutionsTest, TestExpectedOutcome) { - std::stringstream input_buffer, output_buffer; - - // Sanity check, don't call null implementation - ASSERT_NE(implementation, nullptr); - - input_buffer.str(input_data); - - implementation(input_buffer, output_buffer); - - ASSERT_EQ(output_data, output_buffer.str()); -} - -static std::vector get_samples() { - std::vector samples; - for (const auto &entry : std::filesystem::directory_iterator(TEST_SAMPLES_DIR)) { - if (entry.path().filename().extension() == ".in") { - samples.push_back(entry.path().string()); - } - } - - // Ensure a consistent order. - std::sort(samples.begin(), samples.end()); - - return samples; -} - -INSTANTIATE_TEST_CASE_P(DaysTest, SolutionsTest, - testing::ValuesIn(get_samples()), - SolutionsTest::nameInstantiatedTest);