Skip to content

Commit

Permalink
Solution for 2015 Day 2 part 2 (C++)
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Lukas <[email protected]>
  • Loading branch information
SebaLukas committed Dec 23, 2022
1 parent d5833a3 commit 66d4af6
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions 2015/Day2/day2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,26 @@ int main() {
std::string line;
std::vector<int> v_input;
int wrapping_paper_sqfeet = 0;
int actual_box = 0;
int side_l_w, side_w_h, side_h_l = 0;

int total_ribbon = 0;

if (input.good()) {
while (input >> line) {
v_input = split(line, 'x');

side_l_w = v_input[0] * v_input[1];
side_w_h = v_input[1] * v_input[2];
side_h_l = v_input[2] * v_input[0];
int side_l_w = v_input[0] * v_input[1];
int side_w_h = v_input[1] * v_input[2];
int side_h_l = v_input[2] * v_input[0];
std::vector<int> sides {side_l_w, side_w_h, side_h_l};

actual_box = 2 * side_l_w + 2 * side_w_h + 2 * side_h_l + *std::min_element(sides.begin(), sides.end());
wrapping_paper_sqfeet += 2 * side_l_w + 2 * side_w_h + 2 * side_h_l + *std::min_element(sides.begin(), sides.end());

wrapping_paper_sqfeet += actual_box;
std::sort(v_input.begin(), v_input.end());
total_ribbon += v_input[0] + v_input[0] + v_input[1] + v_input[1] + v_input[0] * v_input[1] * v_input[2];

}
}

std::cout << "Total sqaure feet of wrapping paper: " << wrapping_paper_sqfeet;
std::cout << "Total sqaure feet of wrapping paper: " << wrapping_paper_sqfeet << "\n";
std::cout << "Total feet of ribbon: " << total_ribbon << "\n";
}

0 comments on commit 66d4af6

Please sign in to comment.