From b23b0999d636041a5fe471e1ec460bb00e2e8497 Mon Sep 17 00:00:00 2001 From: Bert Peters Date: Sun, 1 Dec 2019 10:50:27 +0100 Subject: [PATCH] Implement day 1. --- 2019/inputs/01.txt | 100 +++++++++++++++++++++++++++++++++++++++++++++ 2019/src/day01.cpp | 20 ++++++++- 2 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 2019/inputs/01.txt diff --git a/2019/inputs/01.txt b/2019/inputs/01.txt new file mode 100644 index 0000000..940774f --- /dev/null +++ b/2019/inputs/01.txt @@ -0,0 +1,100 @@ +102777 +107296 +131207 +116508 +99009 +120098 +83121 +87846 +126604 +79906 +63668 +143932 +51829 +106383 +121354 +138556 +123426 +111544 +84395 +147066 +61897 +133724 +75867 +106697 +67782 +86191 +50666 +138928 +118740 +136863 +123108 +85168 +138487 +115656 +104811 +114986 +147241 +73860 +99186 +134657 +98379 +59914 +144863 +119851 +82549 +93564 +79437 +70761 +134303 +108109 +116208 +80702 +111018 +131996 +119367 +74305 +65905 +116871 +102184 +101880 +100453 +111281 +103134 +129529 +133885 +76153 +56890 +86262 +52804 +139907 +131360 +80009 +121015 +74438 +54470 +73386 +112961 +116283 +81353 +80610 +142522 +64946 +125652 +61688 +58367 +118930 +89711 +115239 +66403 +92405 +114593 +112818 +75964 +126093 +139781 +144801 +88725 +125958 +116869 +119676 diff --git a/2019/src/day01.cpp b/2019/src/day01.cpp index c4ff5e4..457d8a8 100644 --- a/2019/src/day01.cpp +++ b/2019/src/day01.cpp @@ -1,10 +1,26 @@ #include #include "days.hpp" +static inline int required(int weight) { + return weight / 3 - 2; +} + void aoc2019::day01_part1(std::istream &input, std::ostream &output) { - output << "Not implemented\n"; + 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) { - output << "Not implemented\n"; + int total = 0; + for (int current; input >> current;) { + for (int fuel = required(current); fuel > 0; fuel = required(fuel)) { + total += fuel; + } + } + + output << total << std::endl; }