From f2afed267a34b5f0d76e63437d0fcc078d3841b0 Mon Sep 17 00:00:00 2001 From: Thomas Schmucker Date: Sun, 17 Nov 2024 10:49:35 +0100 Subject: aoc 2015, day 15 --- 2015/src/day15.cpp | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 2015/src/day15.cpp 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 @@ +#include +#include +#include +#include + +using namespace std; + +struct Ingredient { + long capacity; + long durability; + long flavor; + long texture; + long calories; +}; + +// NOLINTBEGIN +map Ingredients = { + { "Frosting", { 4, -2, 0, 0, 5 } }, + { "Candy", { 0, 5, -1, 0, 8 } }, + { "Butterscotch", { -1, 0, 5, 0, 6 } }, + { "Sugar", { 0, 0, -2, 2, 1 } } +}; +// NOLINTEND + +void +part1() +{ + long max_score = numeric_limits::min(); + + for ( int frosting = 0; frosting != 100; ++frosting ) { + for ( int candy = 0; candy != 100 - frosting; ++candy ) { + for ( int butterscotch = 0; butterscotch != 100 - frosting - candy; ++butterscotch ) { + int sugar = 100 - butterscotch - candy - frosting; + + if ( sugar < 0 ) { + continue; + } + + auto capacity = Ingredients["Frosting"].capacity * frosting + Ingredients["Candy"].capacity * candy + Ingredients["Butterscotch"].capacity * butterscotch + Ingredients["Sugar"].capacity * sugar; + auto durability = Ingredients["Frosting"].durability * frosting + Ingredients["Candy"].durability * candy + Ingredients["Butterscotch"].durability * butterscotch + Ingredients["Sugar"].durability * sugar; + auto flavor = Ingredients["Frosting"].flavor * frosting + Ingredients["Candy"].flavor * candy + Ingredients["Butterscotch"].flavor * butterscotch + Ingredients["Sugar"].flavor * sugar; + auto texture = Ingredients["Frosting"].texture * frosting + Ingredients["Candy"].texture * candy + Ingredients["Butterscotch"].texture * butterscotch + Ingredients["Sugar"].texture * sugar; + // auto calories = Ingredients["Frosting"].calories * frosting + Ingredients["Candy"].calories * candy + Ingredients["Butterscotch"].calories * butterscotch + Ingredients["Sugar"].calories * sugar; + + auto score = max(0L, capacity) * max(0L, durability) * max(0L, flavor) * max(0L, texture); + + max_score = max(max_score, score); + } + } + } + + cout << max_score << endl; +} + +void +part2() +{ + long max_score = numeric_limits::min(); + + for ( int frosting = 0; frosting != 100; ++frosting ) { + for ( int candy = 0; candy != 100 - frosting; ++candy ) { + for ( int butterscotch = 0; butterscotch != 100 - frosting - candy; ++butterscotch ) { + int sugar = 100 - butterscotch - candy - frosting; + + if ( sugar < 0 ) { + continue; + } + + auto capacity = Ingredients["Frosting"].capacity * frosting + Ingredients["Candy"].capacity * candy + Ingredients["Butterscotch"].capacity * butterscotch + Ingredients["Sugar"].capacity * sugar; + auto durability = Ingredients["Frosting"].durability * frosting + Ingredients["Candy"].durability * candy + Ingredients["Butterscotch"].durability * butterscotch + Ingredients["Sugar"].durability * sugar; + auto flavor = Ingredients["Frosting"].flavor * frosting + Ingredients["Candy"].flavor * candy + Ingredients["Butterscotch"].flavor * butterscotch + Ingredients["Sugar"].flavor * sugar; + auto texture = Ingredients["Frosting"].texture * frosting + Ingredients["Candy"].texture * candy + Ingredients["Butterscotch"].texture * butterscotch + Ingredients["Sugar"].texture * sugar; + auto calories = Ingredients["Frosting"].calories * frosting + Ingredients["Candy"].calories * candy + Ingredients["Butterscotch"].calories * butterscotch + Ingredients["Sugar"].calories * sugar; + + auto score = max(0L, capacity) * max(0L, durability) * max(0L, flavor) * max(0L, texture); + + if ( calories == 500 ) { + max_score = max(max_score, score); + } + } + } + } + cout << max_score << endl; +} + +int +main() +{ + part1(); + part2(); +} -- cgit v1.3