aboutsummaryrefslogtreecommitdiff
path: root/day2.c
diff options
context:
space:
mode:
Diffstat (limited to 'day2.c')
-rw-r--r--day2.c26
1 files changed, 24 insertions, 2 deletions
diff --git a/day2.c b/day2.c
index de96175..d02526f 100644
--- a/day2.c
+++ b/day2.c
@@ -18,17 +18,39 @@ void calcsides(int length, int width, int height, int* side1, int* side2, int* s
(*side3) = height * length;
}
+void calcperi(int edge1, int edge2, int* peri) {
+ (*peri) = 2 * edge1 + 2 * edge2;
+}
+
+void calcarea(int side1, int side2, int side3, int* area) {
+ (*area) = 2*side1 + 2*side2 + 2*side3 + min3(side1, side2, side3);
+}
+
+void calcribbon(int length, int width, int height, int* ribbon) {
+ int bow, wrap;
+ int side1, side2, side3;
+ calcperi(length, width, &side1);
+ calcperi(width, height, &side2);
+ calcperi(height, length, &side3);
+ wrap = min3(side1, side2, side3);
+ bow = length * width * height;
+ (*ribbon) = wrap + bow;
+}
+
int main() {
int length, width, height;
int side1, side2, side3;
int area, totalarea = 0;
+ int ribbon, totalribbon = 0;
while (readsides(&length, &width, &height) > 0) {
calcsides(length, width, height, &side1, &side2, &side3);
- area = 2*side1 + 2*side2 + 2*side3 + min3(side1, side2, side3);
+ calcarea(side1, side2, side3, &area);
+ calcribbon(length, width, height, &ribbon);
totalarea += area;
+ totalribbon += ribbon;
}
- printf("%d\n", totalarea);
+ printf("Total area: %d\nTotal ribbon: %d\n", totalarea, totalribbon);
return 0;
}