about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2017-12-02 16:34:49 +0100
committerLeah Neukirchen <leah@vuxu.org>2017-12-02 16:34:49 +0100
commitd9fb4b56a9bb651a40918ce000075db8257616ee (patch)
tree5ce5a12d343b9721306dc2e12361e80204fe6692
parentbbce6ed5ff8d6ebc36884b205d0bc18a0d991490 (diff)
downloadadventofcode2017-d9fb4b56a9bb651a40918ce000075db8257616ee.tar.gz
adventofcode2017-d9fb4b56a9bb651a40918ce000075db8257616ee.tar.xz
adventofcode2017-d9fb4b56a9bb651a40918ce000075db8257616ee.zip
day01
-rw-r--r--day011
-rw-r--r--day01.cc30
-rw-r--r--day01.k5
3 files changed, 36 insertions, 0 deletions
diff --git a/day01 b/day01
new file mode 100644
index 0000000..cee6ad9
--- /dev/null
+++ b/day01
@@ -0,0 +1 @@
+36743676522426214741687639282183216978128565594112364817283598621384839756628424146779311928318383597235968644687665159591573413233616717112157752469191845757712928347624726438516211153946892241449523148419426259291788938621886334734497823163281389389853675932246734153563861233894952657625868415432316155487242813798425779743561987563734944962846865263722712768674838244444385768568489842989878163655771847362656153372265945464128668412439248966939398765446171855144544285463517258749813731314365947372548811434646381595273172982466142248474238762554858654679415418693478512641864168398722199638775667744977941183772494538685398862344164521446115925528534491788728448668455349588972443295391385389551783289417349823383324748411689198219329996666752251815562522759374542652969147696419669914534586732436912798519697722586795746371697338416716842214313393228587413399534716394984183943123375517819622837972796431166264646432893478557659387795573234889141897313158457637142238315327877493994933514112645586351127139429281675912366669475931711974332271368287413985682374943195886455927839573986464555141679291998645936683639162588375974549467767623463935561847869527383395278248952314792112113126231246742753119748113828843917812547224498319849947517745625844819175973986843636628414965664466582172419197227695368492433353199233558872319529626825788288176275546566474824257336863977574347328469153319428883748696399544974133392589823343773897313173336568883385364166336362398636684459886283964242249228938383219255513996468586953519638111599935229115228837559242752925943653623682985576323929415445443378189472782454958232341986626791182861644112974418239286486722654442144851173538756859647218768134572858331849543266169672745221391659363674921469481143686952478771714585793322926824623482923579986434741714167134346384551362664177865452895348948953472328966995731169672573555621939584872187999325322327893336736611929752613241935211664248961527687778371971259654541239471766714469122213793348414477789271187324629397292446879752673
diff --git a/day01.cc b/day01.cc
new file mode 100644
index 0000000..90a597f
--- /dev/null
+++ b/day01.cc
@@ -0,0 +1,30 @@
+#include <algorithm>
+#include <iostream>
+#include <functional>
+
+int main()
+{
+	std::string d;
+	std::cin >> d;
+
+	d.push_back(d[0]);
+	int s = 0;
+	for (auto i{d.cbegin()};
+	     (i = std::adjacent_find(i, d.cend())) != d.cend();
+	     i++) {
+		s += *i - '0';
+	}
+        std::cout << s << std::endl;
+
+	auto d1{d.cbegin()};
+	auto mid{d1 + d.size()/2 - 1};
+	auto d2{mid + 1};
+	s = 0;
+	for (auto p{std::mismatch(d1, mid, d2, std::not_equal_to<char>())};
+	     p.first != mid;
+	     p = std::mismatch(++p.first, mid, ++p.second, std::not_equal_to<char>()))
+		s += *p.first - '0';
+        std::cout << 2*s << std::endl;
+
+	return 0;
+}
diff --git a/day01.k b/day01.k
new file mode 100644
index 0000000..5dcd379
--- /dev/null
+++ b/day01.k
@@ -0,0 +1,5 @@
+d:(*0:`day01)-"0"
++/d@&d=1_d,*d       / 1069
++/d@&d=,/|2 0N#d    / 1268
+2*+/d@&=/2 0N#d     / 1268, thx jakob for idea
+\\