diff options
author | Leah Neukirchen <leah@vuxu.org> | 2017-12-02 16:34:49 +0100 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2017-12-02 16:34:49 +0100 |
commit | d9fb4b56a9bb651a40918ce000075db8257616ee (patch) | |
tree | 5ce5a12d343b9721306dc2e12361e80204fe6692 /day01.cc | |
parent | bbce6ed5ff8d6ebc36884b205d0bc18a0d991490 (diff) | |
download | adventofcode2017-d9fb4b56a9bb651a40918ce000075db8257616ee.tar.gz adventofcode2017-d9fb4b56a9bb651a40918ce000075db8257616ee.tar.xz adventofcode2017-d9fb4b56a9bb651a40918ce000075db8257616ee.zip |
day01
Diffstat (limited to 'day01.cc')
-rw-r--r-- | day01.cc | 30 |
1 files changed, 30 insertions, 0 deletions
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; +} |