From b84bb5aa6b3139a2a097c7ece914bf1866d6a162 Mon Sep 17 00:00:00 2001 From: Thomas Schmucker Date: Tue, 19 Nov 2024 22:06:52 +0100 Subject: aoc 2015, day 20 --- 2015/src/day20.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 2015/src/day20.cpp diff --git a/2015/src/day20.cpp b/2015/src/day20.cpp new file mode 100644 index 0000000..85e3539 --- /dev/null +++ b/2015/src/day20.cpp @@ -0,0 +1,52 @@ +#include +#include +using namespace std; + +void +part1(int limit) +{ + unordered_map house; + + for ( int i = 1; i < limit / 10; ++i ) { + for ( int j = i; j < limit / 10; j += i ) { + house[j] += i * 10; + } + } + + for ( int i = 0;; ++i ) { + if ( house[i] >= limit ) { + cout << i << endl; + return; + } + } +} + +void +part2(int limit) +{ + unordered_map house; + + for ( int i = 1; i < limit / 10; ++i ) { + int visits = 0; + for ( int j = i; j < limit / 10; j += i ) { + if ( visits++ < 50 ) { + house[j] += i * 11; + } + } + } + + for ( int i = 0;; ++i ) { + if ( house[i] >= limit ) { + cout << i << endl; + return; + } + } +} + +int +main() +{ + static const auto limit = 29000000; + part1(limit); + part2(limit); +} -- cgit v1.3