about summary refs log tree commit diff
path: root/day02.cc
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2017-12-03 17:35:02 +0100
committerLeah Neukirchen <leah@vuxu.org>2017-12-03 17:35:02 +0100
commit49412504eaf8e10fbb1b9f43949a44f69ec199d6 (patch)
treec2598a7e4148cf3ff4655b0c291738a98cf7d1a9 /day02.cc
parent9915f0266673d6186c730e467778524f8ddb1afa (diff)
downloadadventofcode2017-49412504eaf8e10fbb1b9f43949a44f69ec199d6.tar.gz
adventofcode2017-49412504eaf8e10fbb1b9f43949a44f69ec199d6.tar.xz
adventofcode2017-49412504eaf8e10fbb1b9f43949a44f69ec199d6.zip
day02
Diffstat (limited to 'day02.cc')
-rw-r--r--day02.cc31
1 files changed, 31 insertions, 0 deletions
diff --git a/day02.cc b/day02.cc
new file mode 100644
index 0000000..ba955ee
--- /dev/null
+++ b/day02.cc
@@ -0,0 +1,31 @@
+#include <algorithm>
+#include <iostream>
+#include <istream>
+#include <iterator>
+#include <sstream>
+#include <vector>
+
+using namespace std;
+
+int main()
+{
+	string line;
+	int s1 = 0, s2 = 0;
+
+	while (getline(cin, line)) {
+		istringstream is{line};
+		vector<int> v{istream_iterator<int>(is),
+		    istream_iterator<int>()};   // slurp it for part 2
+
+		auto [min, max] = minmax_element(begin(v), end(v));
+		s1 += *max - *min;
+
+		for (int a : v)
+			for (int b : v)
+				if (a > b && a % b == 0)
+					s2 += a / b;
+	}
+
+	cout << s1 << endl << s2 << endl;
+	return 0;
+}