diff options
| author | Thomas Schmucker <ts@its1.de> | 2024-11-19 22:06:52 +0100 |
|---|---|---|
| committer | Thomas Schmucker <ts@its1.de> | 2024-11-19 22:06:52 +0100 |
| commit | b84bb5aa6b3139a2a097c7ece914bf1866d6a162 (patch) | |
| tree | 12f8841c095b8b0140e1197f8c59bda5d3cc9a1d | |
| parent | f52cf2888ddc30c4dc181b88d2a7077ac36f098f (diff) | |
| download | advent-of-code-b84bb5aa6b3139a2a097c7ece914bf1866d6a162.tar.gz advent-of-code-b84bb5aa6b3139a2a097c7ece914bf1866d6a162.tar.bz2 advent-of-code-b84bb5aa6b3139a2a097c7ece914bf1866d6a162.zip | |
aoc 2015, day 20
| -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 | } | ||
