diff options
Diffstat (limited to '2015/src')
| -rw-r--r-- | 2015/src/day20.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
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 @@ | |||
| 1 | #include <iostream> | ||
| 2 | #include <unordered_map> | ||
| 3 | using namespace std; | ||
| 4 | |||
| 5 | void | ||
| 6 | part1(int limit) | ||
| 7 | { | ||
| 8 | unordered_map<int, int> house; | ||
| 9 | |||
| 10 | for ( int i = 1; i < limit / 10; ++i ) { | ||
| 11 | for ( int j = i; j < limit / 10; j += i ) { | ||
| 12 | house[j] += i * 10; | ||
| 13 | } | ||
| 14 | } | ||
| 15 | |||
| 16 | for ( int i = 0;; ++i ) { | ||
| 17 | if ( house[i] >= limit ) { | ||
| 18 | cout << i << endl; | ||
| 19 | return; | ||
| 20 | } | ||
| 21 | } | ||
| 22 | } | ||
| 23 | |||
| 24 | void | ||
| 25 | part2(int limit) | ||
| 26 | { | ||
| 27 | unordered_map<int, int> house; | ||
| 28 | |||
| 29 | for ( int i = 1; i < limit / 10; ++i ) { | ||
| 30 | int visits = 0; | ||
| 31 | for ( int j = i; j < limit / 10; j += i ) { | ||
| 32 | if ( visits++ < 50 ) { | ||
| 33 | house[j] += i * 11; | ||
| 34 | } | ||
| 35 | } | ||
| 36 | } | ||
| 37 | |||
| 38 | for ( int i = 0;; ++i ) { | ||
| 39 | if ( house[i] >= limit ) { | ||
| 40 | cout << i << endl; | ||
| 41 | return; | ||
| 42 | } | ||
| 43 | } | ||
| 44 | } | ||
| 45 | |||
| 46 | int | ||
| 47 | main() | ||
| 48 | { | ||
| 49 | static const auto limit = 29000000; | ||
| 50 | part1(limit); | ||
| 51 | part2(limit); | ||
| 52 | } | ||
