Skip to content

Commit

Permalink
Revert "task: calculate correct values"
Browse files Browse the repository at this point in the history
This reverts commit 54b7af9.
  • Loading branch information
Kjell Gladine committed Nov 25, 2024
1 parent 54b7af9 commit c4b6795
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 42 deletions.
31 changes: 4 additions & 27 deletions Elves.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,23 @@


class Elves {
static int getCubicFeetInVolume(int length, int height, int width);
static int calculateRibbonToWrap(int length, int height, int width);
public:
static int calculateBox(int length ,int height, int width);
static int calculateRibbon(int length ,int height, int width);

int calculateBox(int length ,int height, int width);
};

inline int Elves::getCubicFeetInVolume(int length, int height, int width) {
return (length * width * height);
}

inline int Elves::calculateRibbon(int length ,int height, int width) {
return calculateRibbonToWrap(length,width,height) + getCubicFeetInVolume(length, height, width);
}

inline int Elves::calculateBox(int length, int height, int width) {
int Elves::calculateBox(int length, int height, int width) {
int slack = 0;
int SIDE_ONE = length * width;
int SIDE_TW0 = width * height;
int SIDE_THREE = height * length;
if (SIDE_THREE < SIDE_ONE && SIDE_THREE < SIDE_TW0) {
if (SIDE_THREE > SIDE_ONE && SIDE_THREE > SIDE_TW0) {
slack = SIDE_THREE;
} else if (SIDE_TW0 < SIDE_ONE) {
} else if (SIDE_TW0 > SIDE_ONE) {
slack = SIDE_TW0;
} else {
slack = SIDE_ONE;
}
return (2 * SIDE_ONE) + (2 *SIDE_TW0) + (2 * SIDE_THREE) + slack;
}

inline int Elves::calculateRibbonToWrap(int length, int height, int width) {
if(length >= width && length >= height) {
return (width + width + height + height);
} else if(width >= height) {
return (length + length + height + height);
} else {
return (width + width + length + length);
}
}


#endif //ELVESCALCULATE_H
23 changes: 8 additions & 15 deletions Santa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,19 @@ void doQuestionOne() {
}

void doQuestionTwo() {
Elves elves;
string myText;
ifstream MyReadFile("/Users/rmdy/development/AdventOfCode/params.txt");
int squareFeetOfWrappingPaper = 0;
int squareFeetOfWrappingForRibbon = 0;
while (getline(MyReadFile, myText)) {
string lengthS = myText.substr(0, myText.find('x'));
string widthS = myText.substr(myText.find_first_of('x') + 1, myText.find_last_of('x') - myText.find_first_of('x') - 1);
string heightS = myText.substr(myText.find_last_of('x') + 1);
int lenght = stoi(lengthS);
int width = stoi(widthS);
int height = stoi(heightS);
squareFeetOfWrappingPaper += Elves::calculateBox(lenght,height,width);
squareFeetOfWrappingForRibbon += Elves::calculateRibbon(lenght,height,width);
string length = myText.substr(0, myText.find('x'));
string width = myText.substr(myText.find_first_of('x') + 1, myText.find_last_of('x') - myText.find_first_of('x') - 1);
string height = myText.substr(myText.find_last_of('x') + 1);
cout << "Length " + length << "\n";
cout << "Width " + width << "\n";
cout << "Height " + height << "\n";
std::cout << myText << "\n";
}
MyReadFile.close();
//cout << + squareFeetOfWrappingPaper << "\n";
cout << + squareFeetOfWrappingForRibbon << "\n";
cout << + Elves::calculateRibbon(2,3,4) << "\n";
cout << + Elves::calculateRibbon(1,1,10) << "\n";

}

int main() {
Expand Down

0 comments on commit c4b6795

Please sign in to comment.