aboutsummaryrefslogtreecommitdiff
path: root/2015
diff options
context:
space:
mode:
Diffstat (limited to '2015')
-rw-r--r--2015/src/day15.cpp91
1 files changed, 91 insertions, 0 deletions
diff --git a/2015/src/day15.cpp b/2015/src/day15.cpp
new file mode 100644
index 0000000..dd3aaa4
--- /dev/null
+++ b/2015/src/day15.cpp
@@ -0,0 +1,91 @@
1#include <iostream>
2#include <limits>
3#include <map>
4#include <string>
5
6using namespace std;
7
8struct Ingredient {
9 long capacity;
10 long durability;
11 long flavor;
12 long texture;
13 long calories;
14};
15
16// NOLINTBEGIN
17map<string, Ingredient> Ingredients = {
18 { "Frosting", { 4, -2, 0, 0, 5 } },
19 { "Candy", { 0, 5, -1, 0, 8 } },
20 { "Butterscotch", { -1, 0, 5, 0, 6 } },
21 { "Sugar", { 0, 0, -2, 2, 1 } }
22};
23// NOLINTEND
24
25void
26part1()
27{
28 long max_score = numeric_limits<long>::min();
29
30 for ( int frosting = 0; frosting != 100; ++frosting ) {
31 for ( int candy = 0; candy != 100 - frosting; ++candy ) {
32 for ( int butterscotch = 0; butterscotch != 100 - frosting - candy; ++butterscotch ) {
33 int sugar = 100 - butterscotch - candy - frosting;
34
35 if ( sugar < 0 ) {
36 continue;
37 }
38
39 auto capacity = Ingredients["Frosting"].capacity * frosting + Ingredients["Candy"].capacity * candy + Ingredients["Butterscotch"].capacity * butterscotch + Ingredients["Sugar"].capacity * sugar;
40 auto durability = Ingredients["Frosting"].durability * frosting + Ingredients["Candy"].durability * candy + Ingredients["Butterscotch"].durability * butterscotch + Ingredients["Sugar"].durability * sugar;
41 auto flavor = Ingredients["Frosting"].flavor * frosting + Ingredients["Candy"].flavor * candy + Ingredients["Butterscotch"].flavor * butterscotch + Ingredients["Sugar"].flavor * sugar;
42 auto texture = Ingredients["Frosting"].texture * frosting + Ingredients["Candy"].texture * candy + Ingredients["Butterscotch"].texture * butterscotch + Ingredients["Sugar"].texture * sugar;
43 // auto calories = Ingredients["Frosting"].calories * frosting + Ingredients["Candy"].calories * candy + Ingredients["Butterscotch"].calories * butterscotch + Ingredients["Sugar"].calories * sugar;
44
45 auto score = max(0L, capacity) * max(0L, durability) * max(0L, flavor) * max(0L, texture);
46
47 max_score = max(max_score, score);
48 }
49 }
50 }
51
52 cout << max_score << endl;
53}
54
55void
56part2()
57{
58 long max_score = numeric_limits<long>::min();
59
60 for ( int frosting = 0; frosting != 100; ++frosting ) {
61 for ( int candy = 0; candy != 100 - frosting; ++candy ) {
62 for ( int butterscotch = 0; butterscotch != 100 - frosting - candy; ++butterscotch ) {
63 int sugar = 100 - butterscotch - candy - frosting;
64
65 if ( sugar < 0 ) {
66 continue;
67 }
68
69 auto capacity = Ingredients["Frosting"].capacity * frosting + Ingredients["Candy"].capacity * candy + Ingredients["Butterscotch"].capacity * butterscotch + Ingredients["Sugar"].capacity * sugar;
70 auto durability = Ingredients["Frosting"].durability * frosting + Ingredients["Candy"].durability * candy + Ingredients["Butterscotch"].durability * butterscotch + Ingredients["Sugar"].durability * sugar;
71 auto flavor = Ingredients["Frosting"].flavor * frosting + Ingredients["Candy"].flavor * candy + Ingredients["Butterscotch"].flavor * butterscotch + Ingredients["Sugar"].flavor * sugar;
72 auto texture = Ingredients["Frosting"].texture * frosting + Ingredients["Candy"].texture * candy + Ingredients["Butterscotch"].texture * butterscotch + Ingredients["Sugar"].texture * sugar;
73 auto calories = Ingredients["Frosting"].calories * frosting + Ingredients["Candy"].calories * candy + Ingredients["Butterscotch"].calories * butterscotch + Ingredients["Sugar"].calories * sugar;
74
75 auto score = max(0L, capacity) * max(0L, durability) * max(0L, flavor) * max(0L, texture);
76
77 if ( calories == 500 ) {
78 max_score = max(max_score, score);
79 }
80 }
81 }
82 }
83 cout << max_score << endl;
84}
85
86int
87main()
88{
89 part1();
90 part2();
91}