diff --git a/2015/day02/day02.c b/2015/day02/day02.c index 6490e8a..a54b3f2 100644 --- a/2015/day02/day02.c +++ b/2015/day02/day02.c @@ -1,32 +1,58 @@ #include -int getBoxArea(int l, int w, int h) { +int getBoxSidesArea(int l, int w, int h) { return (2*l*w + 2*w*h + 2*h*l); } -int getSmallestSide(int l, int w, int h) { - if(l < w && l < h) { - return l; +int getSmallestSideArea(int l, int w, int h) { + int smallest = (l * w); + if((l * h) < smallest) { + smallest = (l * h); } - if(w < l && w < h) { - return w; + if((w * h) < smallest) { + smallest = (w * h); } - return h; + return smallest; +} + +int getSmallestPerimeter(int l, int w, int h) { + int use1, use2; + if(l < w || l < h) { + use1 = l; + if(w < h) { + use2 = w; + } else { + use2 = h; + } + } else { + use1 = w; + use2 = h; + } + return (use1 * 2) + (use2 * 2); +} + +int getBoxArea(int l, int w, int h) { + return l * w * h; } void part1() { printf("Part 1\n"); - int floor = 0; char str[100]; int l, w, h, result = 0; while(scanf("%dx%dx%d", &l, &w, &h) > 0) { - result += getBoxArea(l, w, h) + getSmallestSide(l, w, h); + result += getBoxSidesArea(l, w, h) + getSmallestSideArea(l, w, h); } printf("Square Feet Needed: %d\n", result); } void part2() { - printf("Part 1\n"); + printf("Part 2\n"); + char str[100]; + int l, w, h, result = 0; + while(scanf("%dx%dx%d", &l, &w, &h) > 0) { + result += getSmallestPerimeter(l, w, h) + getBoxArea(l, w, h); + } + printf("Ribbon Length Needed: %d\n", result); } int main(int argc, char **argv) {